From 53d9c3bab72f05312d6082b1b68901e2aaea7e6f Mon Sep 17 00:00:00 2001 From: art Date: Wed, 7 Oct 2026 23:09:40 +0500 Subject: [PATCH] faulthandler: accept numeric TOML value for faulthandler_timeout --- changelog/15132.bugfix.rst | 3 +++ src/_pytest/faulthandler.py | 2 +- testing/test_faulthandler.py | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 changelog/15132.bugfix.rst diff --git a/changelog/15132.bugfix.rst b/changelog/15132.bugfix.rst new file mode 100644 index 00000000000..4c2a7b5e6b2 --- /dev/null +++ b/changelog/15132.bugfix.rst @@ -0,0 +1,3 @@ +``faulthandler_timeout`` is now registered with type ``float``, so native TOML +integers and floats (e.g. ``faulthandler_timeout = 5`` in ``pytest.toml``) +are accepted instead of being rejected with ``expects a string, got int``. diff --git a/src/_pytest/faulthandler.py b/src/_pytest/faulthandler.py index 080cf583813..bf32f6ad9b8 100644 --- a/src/_pytest/faulthandler.py +++ b/src/_pytest/faulthandler.py @@ -24,7 +24,7 @@ def pytest_addoption(parser: Parser) -> None: "Exit the test process if a test takes more than " "faulthandler_timeout seconds to finish" ) - parser.addini("faulthandler_timeout", help_timeout, default=0.0) + parser.addini("faulthandler_timeout", help_timeout, type="float", default=0.0) parser.addini( "faulthandler_exit_on_timeout", help_exit_on_timeout, type="bool", default=False ) diff --git a/testing/test_faulthandler.py b/testing/test_faulthandler.py index 67ca221f3f2..15b7abc65b2 100644 --- a/testing/test_faulthandler.py +++ b/testing/test_faulthandler.py @@ -219,3 +219,22 @@ def fileno(self): # Even when the stderr wrapper signals an invalid file descriptor, # ``_get_stderr_fileno()`` should return the real one. assert get_stderr_fileno() == 2 + + +def test_timeout_accepts_native_toml_numbers(pytester: Pytester) -> None: + """faulthandler_timeout is float-typed, so native TOML numbers work (#15132).""" + pytester.makepyprojecttoml( + """ + [tool.pytest] + faulthandler_timeout = 5 + """ + ) + assert pytester.parseconfig().getini("faulthandler_timeout") == 5.0 + + pytester.makepyprojecttoml( + """ + [tool.pytest] + faulthandler_timeout = 2.5 + """ + ) + assert pytester.parseconfig().getini("faulthandler_timeout") == 2.5