Skip to content

Commit 0b89af0

Browse files
tests: add aioresponses for aiohttp response mocking
1 parent c8e12bc commit 0b89af0

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

poetry.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ flake8-todo = "~=0.7"
4545
isort = "^5.9.2"
4646
pep8-naming = "~=0.11"
4747
# testing
48+
aioresponses = "^0.7.2"
4849
codecov = "^2.1.11"
4950
coverage = { extras = ["toml"], version = "^6.0.2" }
5051
pytest = "^6.2.4"

tests/conftest.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import aiohttp
2+
import aioresponses
23
import pytest
34

45

6+
@pytest.fixture
7+
def aioresponse():
8+
"""Fixture to mock aiohttp responses."""
9+
with aioresponses.aioresponses() as aioresponse:
10+
yield aioresponse
11+
12+
513
@pytest.fixture
614
@pytest.mark.asyncio
7-
async def http_session() -> aiohttp.ClientSession:
8-
"""Fixture function for a aiohttp.ClientSession."""
15+
async def http_session(aioresponse) -> aiohttp.ClientSession:
16+
"""
17+
Fixture function for a aiohttp.ClientSession.
18+
19+
Requests fixture aioresponse to ensure that all client sessions do not make actual requests.
20+
"""
921
resolver = aiohttp.AsyncResolver()
1022
connector = aiohttp.TCPConnector(resolver=resolver)
1123
client_session = aiohttp.ClientSession(connector=connector)

0 commit comments

Comments
 (0)