Closed
Description
I got a ScopeMismatch error when tried to add fixture to my test fucntion in a class when I add the scope parameter (scope='class' or scope='module')
:
My case:
import asyncio
import pytest
import pytest_asyncio
from .database import DB
@pytest.fixture(scope='class')
async def db_setup(request):
print("\nconnect to db")
db = await DB.create()
async def resource_teardown():
await db.close()
print("\ndisconnect")
request.addfinalizer(resource_teardown)
return db
class TestDB:
@pytest.mark.asyncio
async def test_connection(self, event_loop, db_setup):
db = await db_setup
with await db._pool as redis:
res = await redis.ping()
print(res)
assert res, "PONG"
And when i run it i get :
ScopeMismatch: You tried to access the 'function' scoped fixture 'event_loop' with a 'class' scoped request object, involved factories
../../../../../.virtualenvs/jwt_auth/lib/python3.5/site-packages/pytest_asyncio/plugin.py:110: def wrapper(*args, **kwargs)
==================================== ERRORS ====================================
___________________ ERROR at setup of TestDB.test_connection ___________________
ScopeMismatch: You tried to access the 'function' scoped fixture 'event_loop' with a 'class' scoped request object, involved factories
../../../../../.virtualenvs/jwt_auth/lib/python3.5/site-packages/pytest_asyncio/plugin.py:110: def wrapper(*args, **kwargs)
============================== 5 tests deselected ==============================
==================== 5 deselected, 1 error in 0.17 seconds =====================
Process finished with exit code 0
I tried to delete the event_loop param but it gave the same error but when i removed scope
parameter from the fixture everithing works
Metadata
Metadata
Assignees
Labels
No labels