diff --git a/Makefile b/Makefile index a8c3d43..53310b2 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,6 @@ format: .PHONY: lint lint: - $(PYTHON) -m ruff $(python_files) + $(PYTHON) -m ruff check $(python_files) $(PYTHON) -m isort --check $(python_files) - $(PYTHON) -m black --check $(python_files) \ No newline at end of file + $(PYTHON) -m black --check $(python_files) diff --git a/README.md b/README.md index 7d017e1..3b4f697 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A pytest plug-in for easy integration of PyStack in your test suite. -It can be used to automatically dump the stack trace of a hanging test in your suite. +It can be used to automatically dump the stack trace of a hanging test in your suite (with exception to test using `pytester` fixture). See [PyStack](https://github.com/bloomberg/pystack) for further information about the tool. diff --git a/src/pytest_pystack/_monitor_process.py b/src/pytest_pystack/_monitor_process.py index 100ec09..b24fa0a 100644 --- a/src/pytest_pystack/_monitor_process.py +++ b/src/pytest_pystack/_monitor_process.py @@ -53,7 +53,12 @@ def _run_monitor(config: PystackConfig, pid, queue): handled_test_cases.add(testcase) try: - if queue.get(timeout=config.threshold) != testcase: + new_testcase = queue.get(timeout=config.threshold) + if new_testcase != testcase: + print( + f"new test {new_testcase} should not start before previous {testcase} test finished", + file=sys.__stderr__, + ) raise Exception( "new test should not start before previous test finished" ) diff --git a/src/pytest_pystack/plugin.py b/src/pytest_pystack/plugin.py index 16a1cd0..1169e47 100644 --- a/src/pytest_pystack/plugin.py +++ b/src/pytest_pystack/plugin.py @@ -62,7 +62,11 @@ def pytest_addoption(parser) -> None: @pytest.hookimpl def pytest_runtest_makereport(item, call): - if call.when in {"setup", "teardown"} and item.config._pystack_queue: + if ( + call.when in {"setup", "teardown"} + and item.config._pystack_queue + and "pytester" not in item.fixturenames + ): item.config._pystack_queue.put(item.name) diff --git a/tests/test_pytest_pystack.py b/tests/test_pytest_pystack.py index 098e471..a495943 100644 --- a/tests/test_pytest_pystack.py +++ b/tests/test_pytest_pystack.py @@ -303,3 +303,38 @@ def test_two_slow_tests_in_a_suite_prints_both(testdir, monkeypatch, capfd): print(stderr) assert "PYSTACK -- test_sleeping_test" in stderr assert "PYSTACK -- test_sleeping_test2" in stderr + + +def test_pytester_compat(testdir, capfd, monkeypatch): + """Make sure that our make_napari_viewer plugin works.""" + + # create a temporary pytest test file + + monkeypatch.chdir(testdir.tmpdir) + testdir.makepyfile( + """ +pytest_plugins = 'pytester' + +test_file =''' +import time + + +def test_sleep(): + time.sleep(1) + assert 1 == 1 +''' + + +def test_pytester(pytester): + pytester.makepyfile(test_file) + result = pytester.runpytest() + result.assert_outcomes(passed=1) + """ + ) + result = testdir.runpytest("--pystack-threshold=3", "-s") + + # check that all 1 test passed + result.assert_outcomes(passed=1) + + _, stderr = capfd.readouterr() + assert not stderr