Skip to content

Commit fa116b2

Browse files
ZhaohuiSselldinesh
authored andcommitted
Catch import error for sai_qualify (#21580)
sai_qualify is skipped in conditional mark file, but pytest still needs to load this file, but it fails to import apscheduler. We have to catch this import error to avoid collection failure for pytest. _________________ ERROR collecting sai_qualify/test_brcm_t0.py _________________ ImportError while importing test module '/var/src/sonic-mgmt_testbed-bjw2-can-t1-7260-11/tests/sai_qualify/test_brcm_t0.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) sai_qualify/test_brcm_t0.py:7: in <module> from .sai_infra import run_case_from_ptf, store_test_result sai_qualify/sai_infra.py:17: in <module> from apscheduler.schedulers.background import BackgroundScheduler E ModuleNotFoundError: No module named 'apscheduler' What is the motivation for this PR? Fix No module named 'apscheduler' How did you do it? Catch ImportError to avoid pytest collection failure. How did you verify/test it? Run it, it's skipped successfully, not failed anymore. collected 5 items sai_qualify/test_sai_ptf_warm_reboot.py::test_sai[None-sainexthopgroup.L3IPv4EcmpHostTwoLagsTest] SKIPPED (It is not tested for now) [ 20%] sai_qualify/test_sai_ptf_warm_reboot.py::test_sai[None-sainexthopgroup.L3IPv4EcmpHostPortLagSharedMembersTest] SKIPPED (It is not tested for now) [ 40%] sai_qualify/test_sai_ptf_warm_reboot.py::test_sai[None-sairif.RifToSubPortTest] SKIPPED (It is not tested for now) [ 60%] sai_qualify/test_sai_ptf_warm_reboot.py::test_sai[None-sairif.SviHostTest] SKIPPED (It is not tested for now) [ 80%] sai_qualify/test_sai_ptf_warm_reboot.py::test_sai[None-sairif.SviLagHostTest] SKIPPED (It is not tested for now) [100%] --------------------------------------------------------------------------------------------------------------------------------- live log teardown --------------------------------------------------------------------------------------------------------------------------------- 05 Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com> Signed-off-by: selldinesh <dinesh.sellappan@keysight.com>
1 parent ff11acc commit fa116b2

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

tests/sai_qualify/sai_infra.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
import pytest
1515
import logging
1616
import time
17-
from apscheduler.schedulers.background import BackgroundScheduler
17+
18+
try:
19+
from apscheduler.schedulers.background import BackgroundScheduler
20+
APSCHEDULER_AVAILABLE = True
21+
except ImportError:
22+
APSCHEDULER_AVAILABLE = False
23+
BackgroundScheduler = None
1824

1925
from .conftest import DUT_WORKING_DIR
2026
from .conftest import USR_BIN_DIR
@@ -96,6 +102,10 @@ def start_warm_reboot_watcher(duthost, request, ptfhost):
96102
request: Pytest request.
97103
ptfhost (AnsibleHost): The PTF server.
98104
"""
105+
if not APSCHEDULER_AVAILABLE:
106+
logger.error("APScheduler module is not available. Cannot start warm reboot watcher.")
107+
pytest.fail("APScheduler module is required for warm reboot functionality but is not installed.")
108+
99109
# install apscheduler before running
100110
logger.info("create and clean up the shared file with ptf")
101111
ptfhost.shell("touch {}".format("/tmp/warm_reboot"))

0 commit comments

Comments
 (0)