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

Emit ResourceWarning on event_loop teardown when loop is unclosed #492

Merged

Conversation

seifertm
Copy link
Contributor

@seifertm seifertm commented Feb 4, 2023

Pytest-asyncio goes to great lengths to be convenient to use. Any kind of event loop mismanagement, such as closed loops when starting a test or finishing a test are handled for the user. This is great from a user experience point of view, but it leaves the user in the dark that something is wrong with their event loop handling.

As outlined in a previous comment, I think that pytest-asyncio should provide more feedback whenever pytest-asyncio takes care of those gotchas.

This PR causes the event_loop fixture to emit a ResourceWarning during teardown when the loop has not been closed. ResourceWarnings are ignored by default, but can be shown with pytest's -W default switch or turned into exceptions with -W error.

When -W error is set, pytest will include the name of the last test. This is easier for users to debug than waiting for CPython to emit the ResourceWarning when the event loop is freed.

The change uncovered a couple of unwanted side-effects in the pytest-asyncio test suite.

…ution of other tests with a custom event loop.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…ardown

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
… fixture finalizer.

The fixture finalizer is invoked once for each fixture, whereas the hook may be invoked multiple times for any specific fixture.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…hesis/test_base

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…t_base using pytester.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
…ent event loop has not been closed.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
… closing the loop and a finalizer for providing a new loop.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
… a single fixture.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
… a single fixture.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
@seifertm seifertm changed the title Emit ResourceWarning on event_loop teardown when loop us unclosed Emit ResourceWarning on event_loop teardown when loop is unclosed Feb 4, 2023
@codecov-commenter
Copy link

Codecov Report

Base: 93.77% // Head: 93.95% // Increases project coverage by +0.17% 🎉

Coverage data is based on head (c66691c) compared to base (1bc34f1).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #492      +/-   ##
==========================================
+ Coverage   93.77%   93.95%   +0.17%     
==========================================
  Files           2        2              
  Lines         273      281       +8     
  Branches       55       55              
==========================================
+ Hits          256      264       +8     
  Misses         11       11              
  Partials        6        6              
Impacted Files Coverage Δ
pytest_asyncio/plugin.py 93.88% <100.00%> (+0.18%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@seifertm seifertm added this pull request to the merge queue Feb 9, 2023
@seifertm seifertm removed this pull request from the merge queue due to the queue being cleared Feb 9, 2023
@seifertm seifertm merged commit d697088 into pytest-dev:master Feb 9, 2023
@seifertm seifertm deleted the feat/resource-warning-on-unclosed-loop branch October 23, 2023 06:15
@seifertm seifertm restored the feat/resource-warning-on-unclosed-loop branch October 23, 2023 08:17
@seifertm seifertm deleted the feat/resource-warning-on-unclosed-loop branch October 23, 2023 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants