pytest-trio icon indicating copy to clipboard operation
pytest-trio copied to clipboard

Add timeout support via pytest-timeout

Open VincentVanlaer opened this issue 2 years ago • 0 comments

Whenever the trio_timeout option is enabled, this plugin will hook into requests from pytest-timeout to set a timeout. It will then start a thread in the background that, after the timeout has reached, will inject a system task in the test loop. This system task will collect stacktraces for all tasks and raise an exception that will terminate the test. The timeout thread is reused for other tests as well to not incur a startup cost for every test.

Since this feature integrates with pytest-timeout, it also honors things like whether a debugger is attached or not.

Drawbacks:

  • Ideally, whether trio does timeouts should not be a global option, but would be better suited for the timeout-method in pytest-timeout. This would require a change in pytest-timeout to let plugins register other timeout methods.
  • This method requires a functioning loop.

Fixes https://github.com/python-trio/pytest-trio/issues/53

VincentVanlaer avatar Sep 03 '23 09:09 VincentVanlaer