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

Fix auto marking of async hypothesis tests in auto mode #259

Merged
merged 2 commits into from Jan 14, 2022

Conversation

seifertm
Copy link
Contributor

The option --asyncio-mode=auto marks all async functions with the asyncio mark during the collection phase. However, when pytest collects the Hypothesis test, the @given decorator has already been applied and the Hypothesis test function is no longer a coroutine.

This commit extends the pytest_pycollect_makeitem hook to mark Hypothesis tests whose function body is a coroutine.

Closes #258

I was uncertain whether to add the tests to the auto mode tests or to the Hypothesis tests. I eventually decided to add them to the tests for the Hypothesis integration. Rather than using pytester I added some assertions so the tests would fail in case we ever change asyncio_mode to something other than auto. Let me know what you think of this.

… Hypothesis test.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
@codecov-commenter
Copy link

Codecov Report

Merging #259 (bd8f210) into master (2e2d5d2) will increase coverage by 0.18%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #259      +/-   ##
==========================================
+ Coverage   92.79%   92.98%   +0.18%     
==========================================
  Files           3        3              
  Lines         222      228       +6     
  Branches       32       32              
==========================================
+ Hits          206      212       +6     
  Misses         10       10              
  Partials        6        6              
Impacted Files Coverage Δ
plugin.py 92.82% <0.00%> (+0.19%) ⬆️

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 2e2d5d2...bd8f210. Read the comment docs.

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.

I can live with it, sure.
The only note: when we change asyncio_mode to strict in setup.cfg these tests will fail.
That's why I personally prefer pytester.

…thout explicit "asyncio" marker when "--asyncio-mode=auto" is set.

The option --asyncio-mode=auto marks all async functions with the asyncio mark during the collection phase. However, when pytest collects the Hypothesis test, the @given decorator has already been applied and the Hypothesis test function is no longer a coroutine.

This commit extends the "pytest_pycollect_makeitem" hook to mark Hypothesis tests whose function body is a coroutine.

Closes pytest-dev#258

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
@seifertm seifertm force-pushed the auto-mode-marks-hypothesis-tests branch from bd8f210 to 732c50b Compare January 14, 2022 09:06
@seifertm
Copy link
Contributor Author

You're right. It's probably a better idea if the tests are decoupled from the project config. I was hoping to avoid the boilerplate that comes with pytester, but maybe we'll find another solution in the future :)

I rewrote the two test cases to use pytester which runs the tests with --asyncio-mode=auto.

@seifertm seifertm merged commit 6cc430c into pytest-dev:master Jan 14, 2022
@seifertm seifertm deleted the auto-mode-marks-hypothesis-tests branch October 23, 2023 06:15
@seifertm seifertm restored the auto-mode-marks-hypothesis-tests branch October 23, 2023 08:17
@seifertm seifertm deleted the auto-mode-marks-hypothesis-tests branch October 23, 2023 08:31
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.

asyncio_mode=auto does not support hypothesis without marker
4 participants