Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable pytest-pystack for test depending on pytester fixture #11

Merged
merged 1 commit into from
Nov 16, 2024
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
$(PYTHON) -m black --check $(python_files)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
7 changes: 6 additions & 1 deletion src/pytest_pystack/_monitor_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
6 changes: 5 additions & 1 deletion src/pytest_pystack/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
35 changes: 35 additions & 0 deletions tests/test_pytest_pystack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading