Skip to content
Myr

test_timeouts.py

This file

Path

tests/test_timeouts.py

44 lines · 1.5 KiB · Python

Last changed by

Add a network pytest mark for tests that use the network (#1669)Antonio Larrosabefore adoption77193b2

History of this file

Take it

The walk stopped after 200 commits: lines older than a783fe5 point at it.

Drop `request.timer` attribute. (#1249)Tom Christiebefore adoptiona783fe5

lines 1–21why, one step back
1import pytest
23import httpx456@pytest.mark.usefixtures("async_environment")7async def test_read_timeout(server):8 timeout = httpx.Timeout(None, read=1e-6)910 async with httpx.AsyncClient(timeout=timeout) as client:11 with pytest.raises(httpx.ReadTimeout):12 await client.get(server.url.copy_with(path="/slow_response"))131415@pytest.mark.usefixtures("async_environment")16async def test_write_timeout(server):17 timeout = httpx.Timeout(None, write=1e-6)1819 async with httpx.AsyncClient(timeout=timeout) as client:20 with pytest.raises(httpx.WriteTimeout):21 data = b"*" * 1024 * 1024 * 100

Seperate `content=...` and `data=...` parameters (#1266)Tom Christiebefore adoptionfeb404f

line 22why, one step back
22 await client.put(server.url.copy_with(path="/slow_response"), content=data)

Drop `request.timer` attribute. (#1249)Tom Christiebefore adoptiona783fe5

lines 23–25why, one step back
23
2425@pytest.mark.usefixtures("async_environment")

Add a network pytest mark for tests that use the network (#1669)Antonio Larrosabefore adoption77193b2

line 26why, one step back
26@pytest.mark.network

Drop `request.timer` attribute. (#1249)Tom Christiebefore adoptiona783fe5

lines 27–44why, one step back
27async def test_connect_timeout(server):
28 timeout = httpx.Timeout(None, connect=1e-6)2930 async with httpx.AsyncClient(timeout=timeout) as client:31 with pytest.raises(httpx.ConnectTimeout):32 # See https://stackoverflow.com/questions/100841/33 await client.get("http://10.255.255.1/")343536@pytest.mark.usefixtures("async_environment")37async def test_pool_timeout(server):38 limits = httpx.Limits(max_connections=1)39 timeout = httpx.Timeout(None, pool=1e-4)4041 async with httpx.AsyncClient(limits=limits, timeout=timeout) as client:42 async with client.stream("GET", server.url):43 with pytest.raises(httpx.PoolTimeout):44 await client.get("http://localhost:8000/")