Open rnusser opened 2 years ago
Same problem here:
Python 3.9.13
aiohttp 3.8.1
aioresponses 0.7.3
pytest 7.1.2
Pytest does a lot of magic things behind the scenes with test functions that take arguments. With pytest
it'd be better to use Pytets fixtures instead of the @aioresponses
decorator:
import asyncio
import aiohttp
import pytest
from aioresponses import aioresponses
@pytest.fixture
def mocked():
with aioresponses() as m:
yield m
def test_request(mocked):
loop = asyncio.get_event_loop()
mocked.get('http://example.com', status=200, body='test')
session = aiohttp.ClientSession()
resp = loop.run_until_complete(session.get('http://example.com'))
assert resp.status == 200
Looks like the README should be updated.
If I run the first example, as it is, I get the error:
However if placed in a class it works:
Python 3.10.4 aiohttp 3.8.1 aioresponses 0.7.3 pytest 7.1.2