http_test_server#

HTTP test server for serving local files during tests.

This module provides a local HTTP server that can be used in pytest fixtures to serve files from a specified directory. The server runs on a random port and supports both IPv4 and IPv6.

The server is commonly used for testing: - Mock conda channels with packages and repodata - Remote environment files (environment.yml) - Remote configuration files - Any scenario where conda needs to fetch files from HTTP URLs

Example usage:

from conda.testing import http_test_server

def test_something():

server = http_test_server.run_test_server("/path/to/files") host, port = server.socket.getsockname()[:2] url = f"http://{host}:{port}/file.txt"

# Make HTTP requests to url...

server.shutdown()

For pytest fixtures that wrap this functionality, see: - http_test_server - function-scoped fixture

The fixture can be configured via @pytest.mark.parametrize("http_test_server", ["<directory>"], indirect=True) to specify the directory to serve, or used without parametrize (or with None) for dynamic content generation.

Functions#

run_test_server(→ http.server.ThreadingHTTPServer)

Run a test server on a random port. Inspect returned server to get port,

Attributes#

run_test_server(directory: str) http.server.ThreadingHTTPServer#

Run a test server on a random port. Inspect returned server to get port, shutdown etc.

server#