From d9347d48b2548b6992c1cb0291c49c21a9f5c48d Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Tue, 1 Nov 2022 02:20:10 +0000 Subject: [PATCH 1/4] Fix UT error under python2 --- test/test_moduleLoad.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_moduleLoad.py b/test/test_moduleLoad.py index 6c0486a7..10e4c9cc 100644 --- a/test/test_moduleLoad.py +++ b/test/test_moduleLoad.py @@ -38,6 +38,6 @@ def test__dbConfig(self): def test_BlockUseSwsssdk(): # Import swsssdk will throw exception with deprecated message. swsssdk_path = os.path.join(modules_path, 'src') - result = subprocess.run(["python", "-c", "import swsssdk;exit()"], capture_output=True, cwd=swsssdk_path) + result = subprocess.check_output(["python", "-c", "import swsssdk;exit()"], stderr=subprocess.STDOUT, cwd=swsssdk_path) - assert "deprecated" in result.stderr.decode("utf-8") + assert "deprecated" in result From 7e51ff85f307521f4a1bb97b8abb7f91aa985822 Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Tue, 1 Nov 2022 02:47:18 +0000 Subject: [PATCH 2/4] Fix UT --- test/test_moduleLoad.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test_moduleLoad.py b/test/test_moduleLoad.py index 10e4c9cc..7a014309 100644 --- a/test/test_moduleLoad.py +++ b/test/test_moduleLoad.py @@ -38,6 +38,10 @@ def test__dbConfig(self): def test_BlockUseSwsssdk(): # Import swsssdk will throw exception with deprecated message. swsssdk_path = os.path.join(modules_path, 'src') - result = subprocess.check_output(["python", "-c", "import swsssdk;exit()"], stderr=subprocess.STDOUT, cwd=swsssdk_path) + result = None + try: + subprocess.check_output(["python", "-c", "import swsssdk;exit()"], stderr=subprocess.STDOUT, cwd=swsssdk_path) + except subprocess.CalledProcessError as e: + result = e.output assert "deprecated" in result From 449dd0c762ee51074beb5805ade106968fa1cff9 Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Tue, 1 Nov 2022 03:30:14 +0000 Subject: [PATCH 3/4] Improve UT --- test/test_moduleLoad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_moduleLoad.py b/test/test_moduleLoad.py index 7a014309..52379eed 100644 --- a/test/test_moduleLoad.py +++ b/test/test_moduleLoad.py @@ -42,6 +42,6 @@ def test_BlockUseSwsssdk(): try: subprocess.check_output(["python", "-c", "import swsssdk;exit()"], stderr=subprocess.STDOUT, cwd=swsssdk_path) except subprocess.CalledProcessError as e: - result = e.output + result = e.output.decode("utf-8") assert "deprecated" in result From 7bf16130baf2622d57efe6b2019fe427d1e92103 Mon Sep 17 00:00:00 2001 From: liuh-80 Date: Tue, 1 Nov 2022 09:37:07 +0000 Subject: [PATCH 4/4] Fix python missing issue --- test/test_moduleLoad.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/test_moduleLoad.py b/test/test_moduleLoad.py index 52379eed..561ec35a 100644 --- a/test/test_moduleLoad.py +++ b/test/test_moduleLoad.py @@ -39,8 +39,13 @@ def test_BlockUseSwsssdk(): # Import swsssdk will throw exception with deprecated message. swsssdk_path = os.path.join(modules_path, 'src') result = None + python_command = "python" + + if sys.version_info.major == 3: + python_command = "python3" + try: - subprocess.check_output(["python", "-c", "import swsssdk;exit()"], stderr=subprocess.STDOUT, cwd=swsssdk_path) + subprocess.check_output([python_command, "-c", "import swsssdk;exit()"], stderr=subprocess.STDOUT, cwd=swsssdk_path) except subprocess.CalledProcessError as e: result = e.output.decode("utf-8")