Comments (5)
We can use this statement to stop the whole session.
request.session.shouldstop = 'time limit reached: %0.2f seconds' % elapsed
Could you describe a bit more the entire process you mean here? Not sure I follow.
Using CI to timeout pytest cannot do a graceful clean and test result report. Thank you.
Have you considered looking if it's possible to get the test reports written out on external termination instead?
from pytest-timeout.
Hi @flub , thanks for your reply and help.
I tried to replace pytest.fail with request.session.shouldstop in the following function to do the concept proof that pytest-timeout could work for pytest session timeout:
def timeout_sigalrm(item, timeout):
"""Dump stack of threads and raise an exception
This will output the stacks of any threads other then the
current to stderr and then raise an AssertionError, thus
terminating the test.
"""
if SUPPRESS_TIMEOUT:
return
__tracebackhide__ = True
nthreads = len(threading.enumerate())
if nthreads > 1:
write_title("Timeout", sep="+")
dump_stacks()
if nthreads > 1:
write_title("Timeout", sep="+")
pytest.fail("Timeout >%ss" % timeout)
The timeout mechanism can stop the whole pytest session.
But I was not sure the original design why pytest-timeout only timeout a test but not providing another option to timeout the whole session.
The use case here:
CI(Jenkins) set a hard timeout, say 5 hrs for pytest jobs. pytest with --junit-xml reports the whole results only after test suite. If the CI timeout was hit and the whole pytest was killed by an external signal, junit test reports were lost.
Two fixes to consider:
- Have a pytest session timeout mechanism and gracefully cleanup for a test suite. Avoid using CI to set external timeout and kill pytest process.
- junitxml plugin report test result after each test, not the whole test suite.
The first fix could fit pytest-timeout domain. That's why I posted an issue here.
The second fix could be in junitxml.py in pytest.
Thank you very much for your reading and time.
from pytest-timeout.
Some context on why pytest-timeout doesn't have this feature: It is my personal opinion that timeouts of this nature (whole test run is taking too long) are the CI system's problem. And I also believe that this should not happen normally and is a serious bug in the test suite if it does. This is the reason that I've never attempted to solve this problem of lost test reporting in case the timeout triggers (the fact that the signal method doesn't have this problem is entirely accidental).
Having said that, I do not oppose if someone would like to contribute such a feature. I'm happy to give feedback on a design and review PRs.
To answer you question about the original design of pytest. It is solving the problem of a test being stuck (the first paragraph of the readme tries to say this: "if you don't know why the test suite hangs"). This kind of problem is a serious bug and that reporting is broken at this point is not much of a concern, once the bug is fixed CI and reporting will be fine again. The concern is showing stack traces so you can debug where the code deadlocked.
I tried to replace pytest.fail with request.session.shouldstop in the following function to do the concept proof that pytest-timeout could work for pytest session timeout
When a signal handler runs, it pushes a new frame on the stack in which it executes. Once that frame returns the previous frame will continue where it left off. If the previous frame was stuck, it will just keep being stuck. pytest.fail() however raises an exception, one which is usually not caught by any of the non-pytest code. So when the frame of the signal handler returns and the exception is set, the exception will usually propagate up the stack until pytest catches it. This is why your modification no longer works: you stopped raising an exception. I suspect this will work better if you insert your shouldstop line before the pytest.fail() call instead of replacing it.
from pytest-timeout.
Hi @flub , thank you very much for your help. You were right. I should insert shouldstop line before the pytest.fail() call.
I will try to make a PR later.
from pytest-timeout.
Going to close this, this essentially asks for graceful termination and graceful termination is explicitly not the domain of pytest-timeout. It's purpose is last-resort termination.
from pytest-timeout.
Related Issues (20)
- `timeout_func_only = true` config does not work HOT 7
- Flask pytest client.post request - timeout error
- is_debugging does not work in VS Code HOT 1
- New Version HOT 9
- how can I get rid of the stack-trace HOT 4
- Question/feature request: way to pause timing HOT 5
- Pytest times out in debug mode with Pycharm 2023.2.1 HOT 1
- pytest timeout in pytest.ini is not working HOT 4
- Measure CPU time instead of wallclock time HOT 4
- Bad and misleading test HOT 2
- subprocess not killed when timeout fires HOT 4
- INTERNALERROR with pytest_configure HOT 2
- feature request: add suite timeout HOT 6
- default branch: master -> main HOT 2
- [QUESTION] When can we expect a release? HOT 3
- [question] hook for executing small bit of code before timeout fires HOT 1
- RFE: is it possible to start making github releases?🤔 HOT 1
- Are timeouts supposed to result in Error or Failure or both? HOT 5
- Suggestion: Using capturemanager.global_and_fixture_disabled HOT 1
- hanging when I use --time-methid=signal
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest-timeout.