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 a warning when a coroutine test function is encountered #4830

Merged
merged 1 commit into from
Mar 15, 2019

Conversation

nicoddemus
Copy link
Member

@nicoddemus nicoddemus commented Feb 25, 2019

Fix #2224

@codecov
Copy link

codecov bot commented Feb 25, 2019

Codecov Report

Merging #4830 into features will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##           features    #4830      +/-   ##
============================================
+ Coverage     95.82%   95.85%   +0.02%     
============================================
  Files           113      113              
  Lines         25213    25229      +16     
  Branches       2490     2491       +1     
============================================
+ Hits          24161    24182      +21     
+ Misses          736      734       -2     
+ Partials        316      313       -3
Impacted Files Coverage Δ
testing/acceptance_test.py 98.03% <100%> (+0.02%) ⬆️
src/_pytest/python.py 93.28% <100%> (+0.08%) ⬆️
src/_pytest/terminal.py 91.8% <0%> (+0.81%) ⬆️

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 951e07d...40072b9. Read the comment docs.

@blueyed blueyed self-requested a review March 5, 2019 22:00
Copy link
Contributor

@blueyed blueyed left a comment

Choose a reason for hiding this comment

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

Please rebase after #4887 for proper coverage report.

@nicoddemus nicoddemus force-pushed the warn-on-coroutine branch 2 times, most recently from 3e61e24 to 2e340e7 Compare March 13, 2019 17:36
@nicoddemus
Copy link
Member Author

Ready for review.

@nicoddemus nicoddemus requested a review from blueyed March 13, 2019 17:37
@@ -156,6 +156,15 @@ def pytest_configure(config):
@hookimpl(trylast=True)
def pytest_pyfunc_call(pyfuncitem):
testfunction = pyfuncitem.obj
iscoroutinefunction = getattr(inspect, "iscoroutinefunction", None)
if iscoroutinefunction is not None and iscoroutinefunction(testfunction):
msg = "test function {} is a coroutine and not natively supported.\n"
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be a format table warning as constant in the warnigns module

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't do that for PytestWarnings in general.

IIRC the objective of concentrating PytestDeprecationWarnings in deprecated.py is to have all of those type of warnings in a single place as a reminder of what we need to remove when the time for a major release comes around.

We don't have the same need for PytestWarning's, because we don't intend to ever remove them, so I don't think it is worth concentrating them in a single place.

Let me know what you think.

Copy link
Member Author

Choose a reason for hiding this comment

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

We should address this in a separate PR if we want to move this forward, as it will affect other warnings as well. 👍

result.stdout.fnmatch_lines(
[
"*test function test_async.py::test_1 is a coroutine*",
"*1 passed, 1 warnings in*",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be counted as "passed" after all?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm you are right.

I suppose the ideal behavior would be to not collect that test at all, but that's not possible, after all the async plugins need that collected.

Should we skip or xfail it, perhaps?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we skip or xfail it, perhaps?

Skipping sounds good to me - but there should probably only be a single skip message (grouped) with -ra - might be the case automatically, when skipping from the same location here, but should have a test.

Copy link
Member Author

Choose a reason for hiding this comment

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

When we skip, should we still show the warning? The warning is a lot more verbose, which doesn't fit with "reason" which is usually a single line...

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO yes. The skip message could state to look at the warning for more details.

Also, having a subclass of PytestWarning for this might make sense, for easier ignoring?!

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, here's the full output of the test:

======================================== warnings summary =========================================
test_async.py::test_1
test_async.py::test_2
  C:\pytest\src\_pytest\python.py:166: PytestWarning: Coroutine functions are not natively supported and have been skipped.
  You need to install a suitable plugin for your async framework, for example:
    - pytest-asyncio
    - pytest-trio
    - pytest-tornasync
    warnings.warn(PytestWarning(msg.format(pyfuncitem.nodeid)))

-- Docs: https://docs.pytest.org/en/latest/warnings.html
============================== 2 skipped, 2 warnings in 0.02 seconds ==============================

Also, having a subclass of PytestWarning for this might make sense, for easier ignoring?!

Indeed, but let's wait to see if there's user requests for that. If we go down that route, it might make sense to make a subclass for each warning emitted by pytest.

Copy link
Contributor

@blueyed blueyed left a comment

Choose a reason for hiding this comment

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

Great!

@nicoddemus nicoddemus merged commit 33d4c96 into pytest-dev:features Mar 15, 2019
@nicoddemus nicoddemus deleted the warn-on-coroutine branch March 15, 2019 12:51
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.

None yet

3 participants