Skip to content

Commit 7ba1c00

Browse files
tests: add tests for aiohttp fixture
1 parent 5cfaf7b commit 7ba1c00

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/test_fixtures.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
import aiohttp
6+
import pytest
7+
8+
9+
if TYPE_CHECKING:
10+
import aioresponses
11+
12+
13+
class TestSessionFixture:
14+
"""Grouping for aiohttp.ClientSession fixture tests."""
15+
16+
@pytest.mark.asyncio
17+
async def test_session_fixture_no_requests(self, http_session: aiohttp.ClientSession):
18+
"""
19+
Test all requests fail.
20+
21+
This means that aioresponses is being requested by the http_session fixture.
22+
"""
23+
url = "https://github.com/"
24+
25+
with pytest.raises(aiohttp.ClientConnectionError):
26+
await http_session.get(url)
27+
28+
@pytest.mark.asyncio
29+
async def test_session_fixture_mock_requests(
30+
self, aioresponse: aioresponses.aioresponses, http_session: aiohttp.ClientSession
31+
):
32+
"""
33+
Test all requests fail.
34+
35+
This means that aioresponses is being requested by the http_session fixture.
36+
"""
37+
url = "https://github.com/"
38+
status = 200
39+
aioresponse.get(url, status=status)
40+
41+
async with http_session.get(url) as resp:
42+
assert status == resp.status

0 commit comments

Comments
 (0)