Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit 73771eb

Browse files
committed
Support both pytest and legacy system test runner
The legacy system test framework uses pytest to execute some tests. Since it'd be quite difficult to convince pytest to decide whether to include conftest.py (or which ones to include when launching from subdir), it makes more sense to have a shared conftest.py which is used by both the legacy test runner invocations of pytest and the new pytest system test runner. It is ugly, but once we drop support for the legacy runner, we'll get rid of it. Properly scope the *port fixtures in order to ensure they'll work as expected with the new pytest runner. Instead of using "session" (which means the fixture is only evaluated once for the entire execution of pytest), use "module" scope, which is evaluated separately for each module. The legacy runner invoked pytest for each system test separately, while the new pytest runner is invoked once for all system tests -- therefore it requires the more fine-grained "module" scope to for the fixtures to work properly. Remove python shebang, as conftest.py isn't supposed to be an executable script.
1 parent d7bcdf8 commit 73771eb

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

bin/tests/system/conftest.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/python3
2-
31
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
42
#
53
# SPDX-License-Identifier: MPL-2.0
@@ -12,25 +10,43 @@
1210
# information regarding copyright ownership.
1311

1412
import os
15-
1613
import pytest
1714

1815

19-
@pytest.fixture(scope="session")
16+
# ======================= LEGACY=COMPATIBLE FIXTURES =========================
17+
# The following fixtures are designed to work with both pytest system test
18+
# runner and the legacy system test framework.
19+
20+
21+
@pytest.fixture(scope="module")
2022
def named_port():
2123
return int(os.environ.get("PORT", default=5300))
2224

2325

24-
@pytest.fixture(scope="session")
26+
@pytest.fixture(scope="module")
2527
def named_tlsport():
2628
return int(os.environ.get("TLSPORT", default=8853))
2729

2830

29-
@pytest.fixture(scope="session")
31+
@pytest.fixture(scope="module")
3032
def named_httpsport():
3133
return int(os.environ.get("HTTPSPORT", default=4443))
3234

3335

34-
@pytest.fixture(scope="session")
36+
@pytest.fixture(scope="module")
3537
def control_port():
3638
return int(os.environ.get("CONTROLPORT", default=9953))
39+
40+
41+
# ======================= PYTEST SYSTEM TEST RUNNER ==========================
42+
# From this point onward, any setting, fixtures or functions only apply to the
43+
# new pytest runner. Ideally, these would be in a separate file. However, due
44+
# to how pytest works and how it's used by the legacy runner, the best approach
45+
# is to have everything in this file to avoid duplication and set the
46+
# LEGACY_TEST_RUNNER if pytest is executed from the legacy framework.
47+
#
48+
# FUTURE: Once legacy runner is no longer supported, remove the env var and
49+
# don't branch the code.
50+
51+
if os.getenv("LEGACY_TEST_RUNNER", "0") == "0":
52+
pass # will be implemented in followup commits

bin/tests/system/run.sh.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ if [ $status -eq 0 ]; then
229229
if start_servers; then
230230
run=$((run+1))
231231
test_status=0
232-
(cd "$systest" && "$PYTEST" -rsxX -v "$test" "$@" || echo "$?" > "$test.status") | SYSTESTDIR="$systest" cat_d
232+
(cd "$systest" && LEGACY_TEST_RUNNER=1 "$PYTEST" -rsxX -v "$test" "$@" || echo "$?" > "$test.status") | SYSTESTDIR="$systest" cat_d
233233
if [ -f "$systest/$test.status" ]; then
234234
if [ "$(cat "$systest/$test.status")" = "5" ]; then
235235
echowarn "R:$systest:SKIPPED"

0 commit comments

Comments
 (0)