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

Resolve event loop closed issue when trying a second attempt with flaky #220

Merged
merged 1 commit into from
Jan 6, 2022
Merged

Conversation

wjsi
Copy link
Contributor

@wjsi wjsi commented Jul 10, 2021

When using flaky along with pytest-asyncio, for instance,

@flaky.flaky(3)
@pytest.mark.asyncio
async def test_errors():
    raise ValueError

when the first attempt failed, the second attempt will raise RuntimeError: Event loop is closed (given box/flaky#166). The reason is that the wrapper

def wrap_in_sync(func, _loop):
will be called twice in pytest_pyfunc_call and the previous closed loop is still used. The resolution is to record the original function and wrap the original function every time.

Fixes #178

@wjsi wjsi changed the title Support flaky on async tests Fix event loop is closed error for flaky Jul 10, 2021
@wjsi wjsi changed the title Fix event loop is closed error for flaky Resolve event loop closed issue when trying a second attempt with flaky Jul 10, 2021
@wjsi
Copy link
Contributor Author

wjsi commented Jul 24, 2021

@Tinche please take a look at this PR :)

Copy link
Contributor

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Another solution can be moving the wrapping from the async test calling stage to tests collection stage.
Might require more lines change though.

@codecov-commenter
Copy link

Codecov Report

Merging #220 (58c7bb5) into master (f21e0da) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #220      +/-   ##
==========================================
+ Coverage   95.86%   95.94%   +0.08%     
==========================================
  Files           2        2              
  Lines         145      148       +3     
==========================================
+ Hits          139      142       +3     
  Misses          6        6              
Impacted Files Coverage Δ
pytest_asyncio/plugin.py 95.91% <100.00%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f21e0da...58c7bb5. Read the comment docs.

@Tinche Tinche merged commit 57ccbc7 into pytest-dev:master Jan 6, 2022
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.

RuntimeError: Event loop is closed
4 participants