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

Warn when an async function is executed without an appropriate plugin #4814

Closed
crusaderky opened this issue Feb 22, 2019 · 3 comments
Closed
Labels
topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch

Comments

@crusaderky
Copy link

In the following code:

async def test1():
    assert Fail

@pytest.mark.asyncio
async def test2():
    assert Fail
  • test1 is silently skipped and marked as successful.
  • test2 follows the same fate if pytest-asyncio is not installed.

Both use cases can be very easily triggered by distraction in real life; the sensible behaviour should be that both tests fail no matter what:

  • Using the @pytest.mark.asyncio decorator without pytest-asyncio installed should cause an error
  • An error should be raised if a test function returns a coroutine
@nicoddemus
Copy link
Member

I agree that we should do something when a function returns a coroutine, but I believe a warning would be better. The warning might even suggest one of the existing async plugins, for example: pytest-asyncio, pytest-trio or pytest-tornasync.

@nicoddemus nicoddemus added type: enhancement new feature or API change, should be merged into features branch topic: reporting related to terminal output and user-facing messages and errors labels Feb 22, 2019
@Zac-HD Zac-HD added the topic: marks related to marks, either the general marks or builtin label Feb 24, 2019
@Zac-HD
Copy link
Member

Zac-HD commented Feb 24, 2019

  • Using the @pytest.mark.asyncio decorator without pytest-asyncio installed should cause an error

You can opt-in to errors on unknown marks with the --strict argument. We should help more though...

@Zac-HD Zac-HD changed the title asyncio tests silently skipped Warn when an async function is executed without an appropriate plugin Feb 25, 2019
@Zac-HD Zac-HD removed the topic: marks related to marks, either the general marks or builtin label Feb 25, 2019
@nicoddemus
Copy link
Member

Closing as duplicate of #2224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

3 participants