Skip to content

Commit 7f008a1

Browse files
authored
Fix UT test_BlockUseSwsssdk() (#128)
#### Why I did it Fix this issue: sonic-net/sonic-buildimage#12558 UT failed under python2: test_BlockUseSwsssdk() > result = subprocess.run(["python", "-c", "import swsssdk;exit()"], capture_output=True, cwd=swsssdk_path) E AttributeError: 'module' object has no attribute 'run' #### How I did it Update UT to use subprocess.check_output(), which support by both python3 and python2. #### How to verify it Pass all UT. #### Which release branch to backport (provide reason below if selected) #### Description for the changelog Fix UT test_BlockUseSwsssdk() #### Link to config_db schema for YANG module changes #### A picture of a cute animal (not mandatory but encouraged)
1 parent e30a1e1 commit 7f008a1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

test/test_moduleLoad.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ def test__dbConfig(self):
3838
def test_BlockUseSwsssdk():
3939
# Import swsssdk will throw exception with deprecated message.
4040
swsssdk_path = os.path.join(modules_path, 'src')
41-
result = subprocess.run(["python", "-c", "import swsssdk;exit()"], capture_output=True, cwd=swsssdk_path)
41+
result = None
42+
python_command = "python"
43+
44+
if sys.version_info.major == 3:
45+
python_command = "python3"
4246

43-
assert "deprecated" in result.stderr.decode("utf-8")
47+
try:
48+
subprocess.check_output([python_command, "-c", "import swsssdk;exit()"], stderr=subprocess.STDOUT, cwd=swsssdk_path)
49+
except subprocess.CalledProcessError as e:
50+
result = e.output.decode("utf-8")
51+
52+
assert "deprecated" in result

0 commit comments

Comments
 (0)