Closed Pac0o closed 6 years ago
@Pac0o yeah, it's a little tricky, but you can achieve that by wrapping it up. like
from py_benchmarks.server import create_app
from pytest_sanic.plugin import test_client as tc
from pytest_sanic.plugin import loop as l
@pytest.fixture(scope="module")
def app():
# yield my_app
return create_app()
@pytest.fixture(scope="module")
def test_client(loop):
return next(tc(loop))
@pytest.fixture(scope="module")
def loop():
return next(l())
@pytest.fixture(scope="module")
def test_cli(loop, app, test_client):
return loop.run_until_complete(test_client(app))
Thank you!
Hi, I was using pytest-sanic to test my app and was trying to use the same loop on all my tests but was unable to do it because when I tried to change the scope of the test_cli function this error appeared.
ScopeMismatch: You tried to access the 'function' scoped fixture 'app' with a 'module' scoped request object, involved factories tests/test_polygon.py:12: def test_cli(loop, app, test_client) .env/lib/python3.5/site-packages/pytest_sanic/plugin.py:39: def loop()
What I ended up doing was modifying the code from plugin.py
Is there any other way of doing this? I did this to improve the speed of the tests.
Thanks