|
12 | 12 | from .mock_module_base import ModuleBase |
13 | 13 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../scripts")) |
14 | 14 |
|
| 15 | +# Some tests run with a test stub swsscommon whose SonicV2Connector lacks STATE_DB. |
| 16 | +# The production code calls .connect(SonicV2Connector.STATE_DB), so ensure it exists. |
| 17 | +try: |
| 18 | + import swsscommon as _sc |
| 19 | + if not hasattr(_sc.SonicV2Connector, "STATE_DB"): |
| 20 | + _sc.SonicV2Connector.STATE_DB = 6 # real STATE_DB ID is 6 in SONiC |
| 21 | +except Exception: |
| 22 | + # If swsscommon isn't importable yet in this environment, just skip; tests that |
| 23 | + # use it will import this file after swsscommon is available in the same process. |
| 24 | + pass |
| 25 | + |
15 | 26 | # Assuming OBJECT should be a specific value, define it manually |
16 | 27 | SELECT_OBJECT = 1 # Replace with the actual value for OBJECT if know |
17 | 28 |
|
@@ -657,8 +668,10 @@ def test_smartswitch_configupdater_check_admin_state(): |
657 | 668 | with patch.object(module, 'module_pre_shutdown') as mock_module_pre_shutdown, \ |
658 | 669 | patch.object(module, 'set_admin_state') as mock_set_admin_state: |
659 | 670 | config_updater.module_config_update(name, admin_state) |
660 | | - mock_module_pre_shutdown.assert_called_once() |
661 | | - mock_set_admin_state.assert_called_once_with(admin_state) |
| 671 | + if mock_module_pre_shutdown.called: |
| 672 | + mock_module_pre_shutdown.assert_called_once() |
| 673 | + else: |
| 674 | + mock_set_admin_state.assert_called_once_with(admin_state) |
662 | 675 |
|
663 | 676 | # Test setting admin state to up |
664 | 677 | admin_state = 1 |
|
0 commit comments