Skip to content
Myr

test_timeouts.py

This file

Path

tests/test_timeouts.py

39 lines · 1.3 KiB · Python

Last changed by

Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d

History of this file

Take it

1import pytest23import httpx456async def test_read_timeout(server, backend):7    timeout = httpx.Timeout(read_timeout=1e-6)89    async with httpx.Client(timeout=timeout) as client:10        with pytest.raises(httpx.ReadTimeout):11            await client.get(server.url.copy_with(path="/slow_response"))121314async def test_write_timeout(server, backend):15    timeout = httpx.Timeout(write_timeout=1e-6)1617    async with httpx.Client(timeout=timeout) as client:18        with pytest.raises(httpx.WriteTimeout):19            data = b"*" * 1024 * 1024 * 10020            await client.put(server.url.copy_with(path="/slow_response"), data=data)212223async def test_connect_timeout(server, backend):24    timeout = httpx.Timeout(connect_timeout=1e-6)2526    async with httpx.Client(timeout=timeout) as client:27        with pytest.raises(httpx.ConnectTimeout):28            # See https://stackoverflow.com/questions/100841/29            await client.get("http://10.255.255.1/")303132async def test_pool_timeout(server, backend):33    pool_limits = httpx.PoolLimits(hard_limit=1)34    timeout = httpx.Timeout(pool_timeout=1e-4)3536    async with httpx.Client(pool_limits=pool_limits, timeout=timeout) as client:37        async with client.stream("GET", server.url):38            with pytest.raises(httpx.PoolTimeout):39                await client.get("http://localhost:8000/")