diff --git a/README.rst b/README.rst index 5fc7c3d..a426d6f 100644 --- a/README.rst +++ b/README.rst @@ -137,10 +137,10 @@ The downsides of this method are that there is a relatively large overhead for running each test and that test runs are not completed. This means that other pytest features, like e.g. JUnit XML output or fixture teardown, will not function normally. The second issue might -be alleviated by using the ``--boxed`` option of the pytest-xdist_ +be alleviated by using the ``--forked`` option of the pytest-forked_ plugin. -.. _pytest-xdist: https://pypi.org/project/pytest-xdist/ +.. _pytest-forked: https://pypi.org/project/pytest-forked/ The benefit of this method is that it will always work. Furthermore it will still provide you debugging information by printing the stacks @@ -392,6 +392,14 @@ to 100 seconds:: Changelog ========= +2.4.0 +----- + +- Detect debuggers registered with sys.monitoring. Thanks Rich + Chiodo. +- Make it clear the timeout message comes from pytest-timeout. Thanks + Pedro Brochado. + 2.3.1 ----- diff --git a/pytest_timeout.py b/pytest_timeout.py index de4878a..7c22069 100644 --- a/pytest_timeout.py +++ b/pytest_timeout.py @@ -21,7 +21,7 @@ __all__ = ("is_debugging", "Settings") SESSION_TIMEOUT_KEY = pytest.StashKey[float]() SESSION_EXPIRE_KEY = pytest.StashKey[float]() - +PYTEST_FAILURE_MESSAGE = "Timeout (>%ss) from pytest-timeout." HAVE_SIGALRM = hasattr(signal, "SIGALRM") if HAVE_SIGALRM: @@ -290,6 +290,10 @@ def is_debugging(trace_func=None): for name in KNOWN_DEBUGGING_MODULES: if any(part.startswith(name) for part in parts): return True + + # For 3.12, sys.monitoring is used for tracing. Check if any debugger has been registered. + if hasattr(sys, "monitoring"): + return sys.monitoring.get_tool(sys.monitoring.DEBUGGER_ID) != None return False @@ -495,7 +499,7 @@ def timeout_sigalrm(item, settings): dump_stacks(terminal) if nthreads > 1: terminal.sep("+", title="Timeout") - pytest.fail("Timeout >%ss" % settings.timeout) + pytest.fail(PYTEST_FAILURE_MESSAGE % settings.timeout) def timeout_timer(item, settings): diff --git a/setup.cfg b/setup.cfg index 914ad08..ac793d8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ name = pytest-timeout description = pytest plugin to abort hanging tests long_description = file: README.rst long_description_content_type = text/x-rst -version = 2.3.1 +version = 2.4.0 author = Floris Bruynooghe author_email = flub@devork.be url = https://github.com/pytest-dev/pytest-timeout @@ -26,6 +26,8 @@ classifiers = Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 + Programming Language :: Python :: 3.13 Topic :: Software Development :: Testing Framework :: Pytest diff --git a/test_pytest_timeout.py b/test_pytest_timeout.py index e768d72..78eb662 100644 --- a/test_pytest_timeout.py +++ b/test_pytest_timeout.py @@ -5,7 +5,10 @@ import pexpect import pytest +from pytest_timeout import PYTEST_FAILURE_MESSAGE + +MATCH_FAILURE_MESSAGE = f"*Failed: {PYTEST_FAILURE_MESSAGE}*" pytest_plugins = "pytester" have_sigalrm = pytest.mark.skipif( @@ -44,7 +47,7 @@ def test_foo(): """ ) result = pytester.runpytest_subprocess("--timeout=1") - result.stdout.fnmatch_lines(["*Failed: Timeout >1.0s*"]) + result.stdout.fnmatch_lines([MATCH_FAILURE_MESSAGE % "1.0"]) def test_thread(pytester): @@ -239,7 +242,7 @@ def test_foo(): """ ) result = pytester.runpytest_subprocess() - result.stdout.fnmatch_lines(["*Failed: Timeout >1.0s*"]) + result.stdout.fnmatch_lines([MATCH_FAILURE_MESSAGE % "1.0"]) def test_timeout_mark_timer(pytester): @@ -480,7 +483,7 @@ def test_foo(): result = child.read().decode().lower() if child.isalive(): child.terminate(force=True) - assert "timeout >1.0s" not in result + assert "timeout (>1.0s)" not in result assert "fail" not in result @@ -524,7 +527,7 @@ def test_foo(): result = child.read().decode().lower() if child.isalive(): child.terminate(force=True) - assert "timeout >1.0s" in result + assert "timeout (>1.0s)" in result assert "fail" in result diff --git a/tox.ini b/tox.ini index 8dbfa6a..6544bbc 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ minversion = 7.0 addopts = -ra [tox] -envlist = py37,py38,py39,py310,py311,py312,pypy3 +envlist = py37,py38,py39,py310,py311,py312,py313,pypy3 [testenv] deps = pytest