Skip to content

Commit f09bd31

Browse files
authored
Fix UT failed cause by change pycommon to use swsscommon (#246)
Fix UT failed cause by change sonic_py_common to use swss_common #### Description Fix UT failed cause by change sonic_py_common to use swss_common: In current UT, we implement swsscommon mock class under sonic-pcied/tests/mocked_libs/swsscommon and load these mock libs by add the mock path in front of real swsscommon lib path with following code: # Add mocked_libs path so that the file under test can load mocked modules from there mocked_libs_path = os.path.join(tests_path, "mocked_libs") sys.path.insert(0, mocked_libs_path) However, because we change sonic_py_common to use swsscommon, so real version of swsscommon been load before we load mock lib. then the UT break with following error message: ______________ TestDaemonPcied.test_update_pcie_devices_status_db ______________ self = <tests.test_DaemonPcied.TestDaemonPcied object at 0x7f29542655d0> @mock.patch('pcied.load_platform_pcieutil', mock.MagicMock()) def test_update_pcie_devices_status_db(self): > daemon_pcied = pcied.DaemonPcied(SYSLOG_IDENTIFIER) tests/test_DaemonPcied.py:160: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ scripts/pcied:93: in __init__ self.device_table = swsscommon.Table(self.state_db, PCIE_DEVICE_TABLE_NAME) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <swsscommon.swsscommon.Table; > args = (<MagicMock name='mock()' id='139815470171344'>, 'PCIE_DEVICE') def __init__(self, *args): > this = _swsscommon.new_Table(*args) E NotImplementedError: Wrong number or type of arguments for overloaded function 'new_Table'. E Possible C/C++ prototypes are: E swss::Table::Table(swss::DBConnector const *,std::string const &) E swss::Table::Table(swss::RedisPipeline *,std::string const &,bool) #### Motivation and Context pyswss will be deprecate, so sonic_py_common will changed to use swss_common. Some UT in this project failed because this change. #### How Has This Been Tested? Pass all UT and sonic-buildimage E2E test. #### Additional Information (Optional)
1 parent c092300 commit f09bd31

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

sonic-pcied/tests/mocked_libs/swsscommon/swsscommon.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,12 @@ def __repr__(self):
5252

5353
def __str__(self):
5454
return repr(self.fv_dict)
55+
56+
class ConfigDBConnector:
57+
pass
58+
59+
class SonicDBConfig:
60+
pass
61+
62+
class SonicV2Connector:
63+
pass

sonic-pcied/tests/test_DaemonPcied.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
else:
1212
import mock
1313

14-
from sonic_py_common import daemon_base
15-
1614
from .mock_platform import MockPcieUtil
1715

1816
SYSLOG_IDENTIFIER = 'pcied_test'
1917
NOT_AVAILABLE = 'N/A'
2018

21-
daemon_base.db_connect = mock.MagicMock()
2219

2320
tests_path = os.path.dirname(os.path.abspath(__file__))
2421

2522
# Add mocked_libs path so that the file under test can load mocked modules from there
2623
mocked_libs_path = os.path.join(tests_path, "mocked_libs")
2724
sys.path.insert(0, mocked_libs_path)
2825

26+
from sonic_py_common import daemon_base
27+
daemon_base.db_connect = mock.MagicMock()
28+
2929
# Add path to the file under test so that we can load it
3030
modules_path = os.path.dirname(tests_path)
3131
scripts_path = os.path.join(modules_path, "scripts")

sonic-pcied/tests/test_pcied.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
else:
1111
from mock import MagicMock, patch, mock_open
1212

13-
from sonic_py_common import daemon_base, device_info
1413
from .mock_platform import MockPcieUtil
1514

1615
tests_path = os.path.dirname(os.path.abspath(__file__))
1716

1817
# Add mocked_libs path so that the file under test can load mocked modules from there
1918
mocked_libs_path = os.path.join(tests_path, "mocked_libs")
2019
sys.path.insert(0, mocked_libs_path)
20+
from sonic_py_common import daemon_base, device_info
2121

2222
# Add path to the file under test so that we can load it
2323
modules_path = os.path.dirname(tests_path)

0 commit comments

Comments
 (0)