diff --git a/python/lib/sift_client/_tests/pytest_plugin/conftest.py b/python/lib/sift_client/_tests/pytest_plugin/conftest.py index 783a12bf4..7afee768d 100644 --- a/python/lib/sift_client/_tests/pytest_plugin/conftest.py +++ b/python/lib/sift_client/_tests/pytest_plugin/conftest.py @@ -9,13 +9,17 @@ block inside ``pytest_configure``, useful for inspecting internal state without running tests against a real backend -Every test in this suite invokes the inner session via -``pytester.runpytest_subprocess(...)`` rather than ``pytester.runpytest(...)``. -``runpytest`` runs the inner pytest in-process, which re-imports the Sift -plugin on each test; the plugin transitively imports numpy, whose C -extensions refuse to initialize twice in one process and raise -``cannot load module more than once per process``. Spawning a subprocess -gives each inner session a fresh interpreter and sidesteps that guard. +The offline-log tests (``test_hierarchy.py``, ``test_pass_fail.py``) drive the +inner session in-process via ``pytester.runpytest_inprocess(...)``. This is +fast because the outer session already preloads the plugin (``pyproject.toml`` +sets ``addopts = "... -p sift_client.pytest_plugin ..."``), so the numpy C +extensions the plugin pulls in are imported once for the whole outer process +and reused by every inner run — no per-test interpreter spawn, and no +``cannot load module more than once per process`` re-init guard to trip. + +Tests that need true process isolation (fresh env vars, credential and +connection resolution, ini parsing) still use ``pytester.runpytest_subprocess(...)`` +so the inner session starts from a clean interpreter. """ from __future__ import annotations diff --git a/python/lib/sift_client/_tests/pytest_plugin/test_hierarchy.py b/python/lib/sift_client/_tests/pytest_plugin/test_hierarchy.py index 1efd4e817..9e0dd52e0 100644 --- a/python/lib/sift_client/_tests/pytest_plugin/test_hierarchy.py +++ b/python/lib/sift_client/_tests/pytest_plugin/test_hierarchy.py @@ -76,7 +76,7 @@ def test_b(self): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -97,7 +97,7 @@ def test_a(self): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=1) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -125,7 +125,7 @@ def test_a(self, v): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -150,7 +150,7 @@ def test_y(self): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -175,7 +175,7 @@ def test_free(): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -205,7 +205,7 @@ def test_b(self): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -230,7 +230,7 @@ def test_b(self): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -252,7 +252,7 @@ def test_a(self): ''' ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=1) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -284,7 +284,7 @@ def test_y(self, w): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -396,7 +396,7 @@ def test_c(self): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2, failed=1) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -434,7 +434,7 @@ def test_b(self): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2, failed=1) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -476,7 +476,7 @@ def test_b(self): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -499,7 +499,7 @@ def test_a(self): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=1) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -524,7 +524,7 @@ def test_a(v): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -565,7 +565,7 @@ def test_y(self): """ ), ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -593,7 +593,7 @@ def test_one(): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=1) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -637,7 +637,7 @@ def test_two(): ) # ``importlib`` import mode is required so two packages with the same # name on disk don't collide during sys.path-based import. - result = pytester.runpytest_subprocess("-v", "--import-mode=importlib") + result = pytester.runpytest_inprocess("-v", "--import-mode=importlib") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -666,7 +666,7 @@ def test_one(): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=1) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -697,7 +697,7 @@ def test_a(self, v): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -730,7 +730,7 @@ def test_rail(v): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -759,7 +759,7 @@ def test_iso(voltage, component): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=4) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -798,7 +798,7 @@ def test_widget(widget): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=2) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -831,7 +831,7 @@ def test_two(w): """ ), ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=4) steps = capture.load_steps(log_file) by_name = _by_name(steps) @@ -855,7 +855,7 @@ def test_chain(a, b): """ ) ) - result = pytester.runpytest_subprocess("-v") + result = pytester.runpytest_inprocess("-v") result.assert_outcomes(passed=1) steps = capture.load_steps(log_file) leaf = next(s for s in steps if s["name"].startswith("b="))