From 5b155eb117d8da113a50fdc2f8588d68dedeb50b Mon Sep 17 00:00:00 2001 From: Rahul Ranjan <11793455+rahul05ranjan@users.noreply.github.com> Date: Wed, 28 Oct 2026 19:43:07 +0530 Subject: [PATCH] fix: accept documented disable_debugger_detection kwarg in timeout marker The timeout marker registration (and the --markers help text) documents a disable_debugger_detection keyword, but _parse_marker() rejected it with 'TypeError: Invalid keyword argument for timeout marker', turning any test using @pytest.mark.timeout(..., disable_debugger_detection=True) into an INTERNALERROR at collection/run time. Parse the keyword (keyword-only, consistent with the documented marker signature) and pass it through so the existing per-marker validation in _get_item_settings() applies to it like the other keyword arguments. Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com> --- pytest_timeout.py | 8 ++++++-- test_pytest_timeout.py | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pytest_timeout.py b/pytest_timeout.py index 192a16c..f127a46 100644 --- a/pytest_timeout.py +++ b/pytest_timeout.py @@ -407,7 +407,7 @@ def _parse_marker(marker): """ if not marker.args and not marker.kwargs: raise TypeError("Timeout marker must have at least one argument") - timeout = method = func_only = NOTSET = object() # noqa: N806 + timeout = method = func_only = disable_debugger_detection = NOTSET = object() # noqa: N806 for kw, val in marker.kwargs.items(): if kw == "timeout": timeout = val @@ -415,6 +415,8 @@ def _parse_marker(marker): method = val elif kw == "func_only": func_only = val + elif kw == "disable_debugger_detection": + disable_debugger_detection = val else: msg = f"Invalid keyword argument for timeout marker: {kw}" raise TypeError(msg) @@ -434,7 +436,9 @@ def _parse_marker(marker): method = None if func_only is NOTSET: func_only = None - return Settings(timeout, method, func_only, None) + if disable_debugger_detection is NOTSET: + disable_debugger_detection = None + return Settings(timeout, method, func_only, disable_debugger_detection) def _validate_timeout(timeout, where): diff --git a/test_pytest_timeout.py b/test_pytest_timeout.py index 178cb3e..7ff4cf6 100644 --- a/test_pytest_timeout.py +++ b/test_pytest_timeout.py @@ -462,6 +462,27 @@ def test_marker_help(pytester): result.stdout.fnmatch_lines(["@pytest.mark.timeout(*"]) +def test_timeout_marker_disable_debugger_detection_keyword(pytester): + # the marker registration documents the disable_debugger_detection + # keyword, so using it must not fail with an invalid-kwarg TypeError + pytester.makepyfile( + """ + import pytest + + @pytest.mark.timeout(60, disable_debugger_detection=True) + def test_marker_kwarg_ok(): + assert True + + @pytest.mark.timeout(60, method="thread", func_only=True, + disable_debugger_detection=True) + def test_marker_kwarg_with_others_ok(): + assert True + """ + ) + result = pytester.runpytest_subprocess() + result.assert_outcomes(passed=2) + + @pytest.mark.parametrize( ("debugging_module", "debugging_set_trace"), [