-
Notifications
You must be signed in to change notification settings - Fork 160
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
file.py is marked to be run in an event loop with scope class, but is not part of any class. #732
Comments
I'm unable to run your specific code example, because it references a bunch of other fixtures and classes I don't know about. However, I can try to explain what triggers the error message. As of v0.23 pytest-asyncio provides one asyncio event loop for collector or item in your test suite (i.e. session, packages, modules, …). This allows tests to run in loops with different scopes. When a test is marked to run in class scope, but there is not surrounding class, pytest-asyncio will report a usage error. For example, the following code would trigger the error you're seeing: import asyncio
import pytest
@pytest.mark.asyncio(scope="class")
async def test_has_no_surrounding_class():
pass In your code, it seems to be the case that the error message is triggered for an async fixture. Unfortunately, pytest-asyncio currently assumes that the fixture scope is related to the event loop scope and couples both together. So maybe you're trying to execute a fixture with scope "class", but the fixture has no surrounding test class? If this is true, then this is a duplicate of #706. |
Thanks for the quick response. Yes, let's close this as a duplicate of #706. |
Hey, these may be related to other issues already opened like #706 or #718. Migrating from 0.21.0 to 0.23.2 (tried also 0.22.0 in between and I don't face any issues with this version).
I have my
test_file.py
file like this:And what I get after running pytest is this
ERROR tests/e2e/test_file.py - _pytest.config.exceptions.UsageError: test_file.py is marked to be run in an event loop with scope class, but is not part of any class.
Opened a new issue, because I didn't see these changes before and it's the first time I see this error, although I extensively searched for it.
Thank you in advance!
The text was updated successfully, but these errors were encountered: