-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add --session-timeout #165
Conversation
Adding WIP because docs need to be updated. |
This is awesome feedback. |
@flub I've made, I think, all suggested changes except the timeout location. Again, thanks so much for your feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be added to the pytest_report_header
as well. Or maybe only if it is set to keep the noise down
pytest_timeout.py
Outdated
@@ -18,6 +19,7 @@ | |||
|
|||
|
|||
__all__ = ("is_debugging", "Settings") | |||
suite_timeout_key = pytest.StashKey[float]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about pytest's Stash
. As this is a module-level constant though could it be upper case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uppercase is fine with me. I was going by convention of uses of StashKey in pytest-dev: https://github.com/search?q=org%3Apytest-dev%20pytest.StashKey&type=code
However, I like it uppercase. good call.
pytest_timeout.py
Outdated
@@ -507,3 +534,12 @@ def dump_stacks(terminal): | |||
thread_name = "<unknown>" | |||
terminal.sep("~", title="Stack of %s (%s)" % (thread_name, thread_ident)) | |||
terminal.write("".join(traceback.format_stack(frame))) | |||
|
|||
|
|||
def pytest_runtest_makereport(item, call): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this hook is apparently called many times for a single test, see CallInfo
. Furthermore this hook is documented to "stop at first non-None result". are you sure this hook will always correctly interact with the hook that writes to the terminal or whatever output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a test for if call.when == "teardown"
so it's only called once per test.
I can also add a hookimpl(tryfirst=True)
to try to ensure that other hooks that might return non-None run after this one.
But really, I don't think there are guarantees
I'm not sure I follow this yet. The docs I can find say:
Looking at What am I missing? |
good idea. I usually run with |
What I'd really like is a hook right before Example: However, if we check for timeout in If we check timeout in So I picked the hook that can be checked after the teardown, and that really is only |
pytest_timeout.py
Outdated
|
||
suite_timeout = config.getoption("--suite-timeout") | ||
if suite_timeout: | ||
timeout_header.append("suite timeout: %ss" % suite_timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add some tests for this? I suspect you missed some newlines here.
Right, let's make a test for exactly this scenario so we can play with this and make sure it behaves right. A test with two tests, and the suite-timeout is expected to trigger during the first test. Because while I entirely agree with all your logic and desire to when to interrupt, I still don't understand what the thing is that stops the check from being added at the end of
I think when using the |
@flub Thanks for your patience with me and this PR. I've moved the suite timeout check to Question: Does it make sense to call this flag It just occurred to me that the rest of pytest generally uses the term "session" instead of "suite". |
I'm going to assume you agree that |
Thanks for keeping at it! And bearing with my slow responses (I've been ill in between as well :( )
Glad to see this is working out! I think the changes are much simpler now.
Yep, that's probably better. I think there are a few more tests that would be really helpful to make sure this behaves right:
|
First, I added a test that would do the 2 test thing, with a slow fixture also, with this comment:
Then I realized that's also sufficient to test the timeout, so I just changed the one existing test to do that. Second, I extended |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Maybe time to start editing the README :)
test_pytest_timeout.py
Outdated
# So about 1.5 seconds per test, ~3 sec total, | ||
# Therefore: | ||
# A timeout of 1.25 sec should happen during the teardown of the first test | ||
# and the second test should NOT be run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this is asserted? not immediately sure how you would assert it, maybe with more verbose output and more output lines to match. or maybe there's something easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this is addressed yet?
test_pytest_timeout.py
Outdated
# each using a fixture with 0.5 sec setup and 0.5 sec teardown | ||
# So about 1.5 seconds per test, ~3 sec total, | ||
# Therefore: | ||
# A timeout of 1.25 sec should happen during the teardown of the first test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.25 from an edge is too brittle. experience tells me you can't really work with sub-seconds times in this test suite, it gets flaky otherwise.
Make the total test duration 2s and the session timeout 1s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the numbers in this description are now wrong. maybe just describe that this is designed to timeout during the first test and ensure the first test still runs to completion but the 2nd test is not started?
I'm really not sure where the right place to put the Session Timeout info in the docs, so I just:
When modifying the changelog I noticed the ini file setting for timeout, and figured session_timeout would also be good. So I added that to the code and added an inifile test for session_timeout |
test_pytest_timeout.py
Outdated
# each using a fixture with 0.5 sec setup and 0.5 sec teardown | ||
# So about 1.5 seconds per test, ~3 sec total, | ||
# Therefore: | ||
# A timeout of 1.25 sec should happen during the teardown of the first test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the numbers in this description are now wrong. maybe just describe that this is designed to timeout during the first test and ensure the first test still runs to completion but the 2nd test is not started?
test_pytest_timeout.py
Outdated
# So about 1.5 seconds per test, ~3 sec total, | ||
# Therefore: | ||
# A timeout of 1.25 sec should happen during the teardown of the first test | ||
# and the second test should NOT be run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this is addressed yet?
@okken ping, would be nice to see this merged. i was kind of waiting for this to publish a release. unless you think it'll take longer and i should release without waiting? |
@flub thanks for the ping. I have so much going on and this slipped through the cracks. |
I just pushed up some changes. All doc and/or comment changes |
Feel free to modify any wording as you see fit to expedite the release |
I'm pretty sure I addressed any concerns. |
Thanks for the work and bearing with me! |
For pytest-dev/pytest-timeout#165. [no changelog]
For pytest-dev/pytest-timeout#165. [no changelog]
Addresses request #163