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: 11 additions & 7 deletions python/lib/sift_client/_tests/pytest_plugin/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 24 additions & 24 deletions python/lib/sift_client/_tests/pytest_plugin/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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="))
Expand Down
Loading