You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pytest failing - ScopeMismatch: You tried to access the 'function' scoped fixture 'event_loop' with a 'session' scoped request object, involved factories#638
Describe the bug
Trying to add testing with pytest, getting ScopeMismatch: You tried to access the 'function' scoped fixture 'event_loop' with a 'session' scoped request object, involved factories.
I understand that I'm probably doing something wrong but the documentation only covers the initializer and not how to run tests with pytest, so if anyone could point me to an example that would be great!
To Reproduce
import pytest
import os
from tortoise.contrib import test
from tortoise.contrib.test import finalizer, initializer
from models import User
@pytest.fixture(scope="session", autouse=True)
@pytest.mark.asyncio
async def initialize_tests(request):
db_url = os.environ.get("TORTOISE_TEST_DB", "sqlite://:memory:")
initializer(["models"], db_url=db_url, app_label="models")
request.addfinalizer(finalizer)
await User.create(username="joebloggs",
firstname="Joe",
lastname="Bloggs",
admin=False,
email="joe@example.com",
pw_hash="test")
@pytest.mark.asyncio
async def test_something():
u1 = await User.all().first()
assert u1.username == "joebloggs"
Expected behavior
Test should run successfully
Additional context
I have tried using pytest with the
from tortoise.contrib import test
class TestSomething(test.TestCase):
def test_something(self):
which also failed.
Also getting warning
asynctest/mock.py:434: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
def wait(self, skip=0):
which i think has been mentioned in another issue and is not fatal (and not related to my issue but thought id mention it for full context)
The text was updated successfully, but these errors were encountered:
I got this error as well, it seems to be related to defining an async fixture with a non-function scope, from pytest-asyncio's README
All scopes are supported, but if you use a non-function scope you will need to redefine the event_loop fixture to have the same or broader scope. Async fixtures need the event loop, and so must have the same or narrower scope than the event_loop fixture.
So the solution is to redefine the event_loop fixture to have a session scope:
Describe the bug
Trying to add testing with pytest, getting
ScopeMismatch: You tried to access the 'function' scoped fixture 'event_loop' with a 'session' scoped request object, involved factories
.I understand that I'm probably doing something wrong but the documentation only covers the initializer and not how to run tests with pytest, so if anyone could point me to an example that would be great!
To Reproduce
Expected behavior
Test should run successfully
Additional context
I have tried using pytest with the
which also failed.
Also getting warning
which i think has been mentioned in another issue and is not fatal (and not related to my issue but thought id mention it for full context)
The text was updated successfully, but these errors were encountered: