Skip to content

Commit

Permalink
unittest - fix import for python 2 (#139)
Browse files Browse the repository at this point in the history
Submodule update failed for python 2 because mock import statement is not compatible for python 2
Fix import statement for python 2 and python 3

Passed UT for python 2 and python 3
```
platform linux2 -- Python 2.7.16, pytest-3.10.1, py-1.7.0, pluggy-0.8.0
rootdir: /sonic/src/sonic-py-swsssdk, inifile: pytest.ini
plugins: cov-2.6.0
collected 7 items

test/sonic_db_dump_load_test.py ..                                                     [ 28%]
test/test_moduleLoad.py ....                                                           [ 85%]
test/test_port_util.py .                                                               [100%]


platform linux -- Python 3.9.2, pytest-6.0.2, py-1.10.0, pluggy-0.13.0
rootdir: /sonic/src/sonic-py-swsssdk, configfile: pytest.ini
plugins: pyfakefs-5.2.2, cov-2.10.1
collected 7 items

test/sonic_db_dump_load_test.py ..                                                     [ 28%]
test/test_moduleLoad.py ....                                                           [ 85%]
test/test_port_util.py .                                                               [100%]
```
  • Loading branch information
maipbui authored May 17, 2023
1 parent 30075a4 commit 92991f0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/sonic_db_dump_load_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os
import sys
import pytest
from unittest.mock import patch, MagicMock
if sys.version_info.major == 3:
from unittest import mock
else:
import mock
from mock import patch, MagicMock

modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(modules_path, 'src'))
Expand Down

0 comments on commit 92991f0

Please sign in to comment.