Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from tests.common.cache import FactsCache
from tests.common.config_reload import config_reload
from tests.common.connections.console_host import ConsoleHost
from tests.common.helpers.assertions import pytest_assert as pt_assert

try:
from tests.macsec import MacsecPlugin
Expand All @@ -63,6 +64,8 @@
logger = logging.getLogger(__name__)
cache = FactsCache()

DUTHOSTS_FIXTURE_FAILED_RC = 15

pytest_plugins = ('tests.common.plugins.ptfadapter',
'tests.common.plugins.ansible_fixtures',
'tests.common.plugins.dut_monitor',
Expand Down Expand Up @@ -314,6 +317,12 @@ def get_specified_duts(request):
return duts


def pytest_sessionfinish(session, exitstatus):
if session.config.cache.get("duthosts_fixture_failed", None):
session.config.cache.set("duthosts_fixture_failed", None)
session.exitstatus = DUTHOSTS_FIXTURE_FAILED_RC


@pytest.fixture(name="duthosts", scope="session")
def fixture_duthosts(enhance_inventory, ansible_adhoc, tbinfo, request):
"""
Expand All @@ -323,7 +332,14 @@ def fixture_duthosts(enhance_inventory, ansible_adhoc, tbinfo, request):
mandatory argument for the class constructors.
@param tbinfo: fixture provides information about testbed.
"""
return DutHosts(ansible_adhoc, tbinfo, get_specified_duts(request))
try:
host = DutHosts(ansible_adhoc, tbinfo, get_specified_duts(request))
return host
except BaseException as e:
logger.error("Failed to initialize duthosts.")
request.config.cache.set("duthosts_fixture_failed", True)
pt_assert(False, "!!!!!!!!!!!!!!!! duthosts fixture failed !!!!!!!!!!!!!!!!"
"Exception: {}".format(repr(e)))


@pytest.fixture(scope="session")
Expand Down
5 changes: 5 additions & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ function run_individual_tests()
echo "=== Sanity check failed for $test_script. Skip rest of the scripts if there is any. ==="
return ${ret_code}
fi
# rc 15 means duthosts fixture failed
if [ ${ret_code} -eq 15 ]; then
echo "=== duthosts fixture failed for $test_script. Skip rest of the scripts if there is any. ==="
return ${ret_code}
fi

EXIT_CODE=1
if [[ ${TEST_MAX_FAIL} != 0 ]]; then
Expand Down