Skip to content

Accept datetime.timedelta as the timeout marker value - #219

Open
mokhan2k-spec wants to merge 1 commit into
pytest-dev:mainfrom
mokhan2k-spec:fix/80-timedelta-marker
Open

mokhan2k-spec wants to merge 1 commit into
pytest-dev:mainfrom
mokhan2k-spec:fix/80-timedelta-marker

Conversation

@mokhan2k-spec

Copy link
Copy Markdown

Reopened from my project account (@mokhan2k-spec). This supersedes #218, which I've closed. The change is the same; only the commit author moved to this account.

What: @pytest.mark.timeout(datetime.timedelta(minutes=5)) (and timeout=timedelta(...)) now works. A timedelta is converted with total_seconds(); numbers and strings behave exactly as before.

Why: #80. With @pytest.mark.timeout(300) the unit is invisible at the call site. Before this change a timedelta crashed the run with TypeError: float() argument must be a string or a real number, not 'datetime.timedelta' (an INTERNALERROR, because _validate_timeout only caught ValueError).

How: one isinstance(timeout, datetime.timedelta) branch at the top of _validate_timeout, which every source (marker, ini, env, CLI) goes through. README gets a short example under the marker option. I kept the scope to the form the maintainer said would be acceptable; I did not add the seconds=/minutes= keyword form discussed in the issue.

Tested: new tests test_timeout_mark_timedelta (positional and keyword, short timedelta, asserts the thread-method timeout fires) and test_timeout_mark_timedelta_not_exceeded (5 minute timedelta, test passes). They fail before the change and pass after. Full suite and pre-commit pass.

Fixes #80

🤖 Generated with Claude Code

The timeout marker only took a number of seconds, so the unit was not
visible at the call site. A timedelta is now converted with
total_seconds(), e.g. @pytest.mark.timeout(datetime.timedelta(minutes=5)).

Fixes pytest-dev#80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make timeout duration unit self-documenting

1 participant