Skip to content
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

Test timeout via marker kwargs #215

Open
fjetter opened this issue May 25, 2021 · 2 comments
Open

Test timeout via marker kwargs #215

fjetter opened this issue May 25, 2021 · 2 comments
Labels

Comments

@fjetter
Copy link

fjetter commented May 25, 2021

At dask.distributed we started using pytest-asyncio for increasingly many tests. Before this, we've been decorating our plain asyncio tests using our own decorator which is not unlike to what pytest-asyncio is using under the hood, see https://github.com/dask/distributed/blob/833c5f6c040feaa4550fa343d8e6e4feef3f84d5/distributed/utils_test.py#L753-L772 but that has the obvious shortcoming that it doesn't integrate that nicely into pytest.

For our use case the timeout argument is very important since many tests are waiting until certain conditions are true. Moving to pytest-asyncio required us to use https://pypi.org/project/pytest-timeout/ but for portability reasons this plugin terminates the entire test process if a single test timeouts (see thread vs signal in their docs) which is not great.

A better integration with asyncio would be relatively easy to achieve and would allow us to improve our integration with pytest further. The syntax I had in mind is simply

@pytest.mark.asyncio(timeout=30)
async def test_requires_timeout():
    await stuff()

which, under the hood, would wrap the coro with https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for and would raise an asyncio.TimeoutError if the test runs for too long.
A default value for this timeout could be provided via a configuration file or similar.

If this overlap in scope is acceptable for this repo I would prepare and open a PR.

@Tinche
Copy link
Member

Tinche commented May 25, 2021

Interesting, I'd be open to something like that!

@johnthagen
Copy link

johnthagen commented Jun 6, 2023

Wanted to echo this comment from the related PR:

It would be important to also allow disabling the timeout during an interactive debugging session, otherwise if you step into a function that is awaited and stop at a break point, the timeout will fire by the time you return causing the rest of the test to fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants