Skip to content

Test Server & Testing Support ## Business Purpose

Provide a lightweight HTTP/HTTPS test server framework for integration testing of the requests library and custom adapters. ## Current Behaviors - Server class (in tests/testserver/server.py) is a threaded server that handles requests via a callback (handler) function tests/testserver/server.py:25. - TLSServer subclass adds SSL/TLS support with mutual TLS option tests/testserver/server.py:139. - conftest.py provides fixtures httpbin, httpbin_secure, nosan_server for integration tests (tests/conftest.py:15-22,45-67). - test_utils.py provides override_environ context manager for environment variable mocking tests/utils.py:6. - Tests cover all major capabilities: adapters, sessions, cookies, auth, timeouts, redirects, headers, URLs, utilities (tests/test_*.py). ## Technical Implementation The test server uses raw sockets and select for non-blocking I/O. Fixtures in conftest.py set up and tear down the server and clean environment variables. ## Definition of Done - The test server can be used as a context manager and returns a (host, port) tuple. - A request to the test server returns the expected response as defined by the handler. - TLS server with a self-signed certificate can be used for SSL tests. - Environment variables are cleaned before each test via clean_proxy_environ fixture. - The test server correctly handles multiple connections within its configured requests_to_handle.