Skip to content

Commit aa6e3ad

Browse files
Czakipablogsal
authored andcommitted
Disable pytest-pystack for test depending on pytester fixture
This is only a workaround, maybe a better solution will be to implement some stack mechanism, that will be enabled if pytester fixture is used. Signed-off-by: Grzegorz Bokota <bokota+github@gmail.com>
1 parent 77e9a06 commit aa6e3ad

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ format:
1414

1515
.PHONY: lint
1616
lint:
17-
$(PYTHON) -m ruff $(python_files)
17+
$(PYTHON) -m ruff check $(python_files)
1818
$(PYTHON) -m isort --check $(python_files)
19-
$(PYTHON) -m black --check $(python_files)
19+
$(PYTHON) -m black --check $(python_files)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
A pytest plug-in for easy integration of PyStack in your test suite.
1414

15-
It can be used to automatically dump the stack trace of a hanging test in your suite.
15+
It can be used to automatically dump the stack trace of a hanging test in your suite (with exception to test using `pytester` fixture).
1616

1717
See [PyStack](https://github.com/bloomberg/pystack) for further information about the tool.
1818

src/pytest_pystack/_monitor_process.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ def _run_monitor(config: PystackConfig, pid, queue):
5353
handled_test_cases.add(testcase)
5454

5555
try:
56-
if queue.get(timeout=config.threshold) != testcase:
56+
new_testcase = queue.get(timeout=config.threshold)
57+
if new_testcase != testcase:
58+
print(
59+
f"new test {new_testcase} should not start before previous {testcase} test finished",
60+
file=sys.__stderr__,
61+
)
5762
raise Exception(
5863
"new test should not start before previous test finished"
5964
)

src/pytest_pystack/plugin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ def pytest_addoption(parser) -> None:
6262

6363
@pytest.hookimpl
6464
def pytest_runtest_makereport(item, call):
65-
if call.when in {"setup", "teardown"} and item.config._pystack_queue:
65+
if (
66+
call.when in {"setup", "teardown"}
67+
and item.config._pystack_queue
68+
and "pytester" not in item.fixturenames
69+
):
6670
item.config._pystack_queue.put(item.name)
6771

6872

tests/test_pytest_pystack.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,38 @@ def test_two_slow_tests_in_a_suite_prints_both(testdir, monkeypatch, capfd):
303303
print(stderr)
304304
assert "PYSTACK -- test_sleeping_test" in stderr
305305
assert "PYSTACK -- test_sleeping_test2" in stderr
306+
307+
308+
def test_pytester_compat(testdir, capfd, monkeypatch):
309+
"""Make sure that our make_napari_viewer plugin works."""
310+
311+
# create a temporary pytest test file
312+
313+
monkeypatch.chdir(testdir.tmpdir)
314+
testdir.makepyfile(
315+
"""
316+
pytest_plugins = 'pytester'
317+
318+
test_file ='''
319+
import time
320+
321+
322+
def test_sleep():
323+
time.sleep(1)
324+
assert 1 == 1
325+
'''
326+
327+
328+
def test_pytester(pytester):
329+
pytester.makepyfile(test_file)
330+
result = pytester.runpytest()
331+
result.assert_outcomes(passed=1)
332+
"""
333+
)
334+
result = testdir.runpytest("--pystack-threshold=3", "-s")
335+
336+
# check that all 1 test passed
337+
result.assert_outcomes(passed=1)
338+
339+
_, stderr = capfd.readouterr()
340+
assert not stderr

0 commit comments

Comments
 (0)