pytest-socket is a pytest plugin that allows you to disable real socket connections during test runs. This helps ensure your tests are truly isolated, do not make unintended network calls, and are faster by avoiding I/O. It is currently at version 0.7.0 and has a moderate release cadence, with updates addressing compatibility and new features.
pip install pytest-socketNo compatibility data collected yet for this library.
This quickstart demonstrates the default behavior of `pytest-socket` blocking network connections and how to selectively re-enable them using `pytest.mark.enable_socket` or the `socket_enabled` fixture. It also shows how CLI flags like `--disable-socket` and `--allow-socket` influence test execution.
Upgrade Python to >=3.8 or pin `pytest-socket` to a compatible version for your Python environment (e.g., `pip install 'pytest-socket<0.6.0'`).
Ensure your `pytest` version is 7.0.0 or newer, or pin `pytest-socket` to a version compatible with your `pytest` installation (e.g., `pip install 'pytest-socket<0.6.0'`).
Use `--allow-socket`, `--allow-hosts=host1,host2`, `pytest.mark.enable_socket`, or the `socket_enabled` fixture to explicitly permit network activity for specific tests or the entire test suite.
Upgrade to `pytest-socket >=0.5.1` to resolve doctest compatibility issues.
Upgrade to `pytest-socket >=0.5.0` to ensure proper compatibility with `httpx`.
Be aware that `--force-enable-socket` takes precedence. If you intend to rigorously test network blocking, avoid using this flag or understand its implications.