Repository navigation
Accept datetime.timedelta as the timeout marker value - #219
Open
mokhan2k-spec wants to merge 1 commit into
Open
mokhan2k-spec wants to merge 1 commit into
mokhan2k-spec wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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))(andtimeout=timedelta(...)) now works. A timedelta is converted withtotal_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 withTypeError: float() argument must be a string or a real number, not 'datetime.timedelta'(an INTERNALERROR, because_validate_timeoutonly caughtValueError).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 theseconds=/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) andtest_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