--- id: pytest-socket version: "0.8.0" license: MIT license_treatment: permissive maintenance: active --- # pytest-socket — Pytest Plugin to disable socket calls during tests License: permissive · Maintenance: active · Downloads: 13.9M/mo ## What it is and what it does pytest-socket is a pytest plugin that intercepts Python's socket interface to prevent network calls during test execution. It works by globally disabling socket access or by restricting connections to an allowlist of specific hosts, IP addresses, or CIDR ranges. You can apply these restrictions via CLI flags (like `--disable-socket`), pytest configuration files, or per-test via fixtures and markers. The plugin is useful for ensuring tests remain isolated and deterministic by catching accidental or unintended network dependencies. It supports selective allowlisting, Unix domain socket access for async testing, and per-test overrides. The plugin has been actively maintained since 2017 and supports Python 3.10 through 3.14. Use it for: - Catch tests that accidentally make real HTTP requests to external APIs instead of using mocks. - Enforce network isolation in CI/CD pipelines to ensure tests don't depend on external services. - Allow specific tests to connect to localhost or a test server while blocking all other network access. - Verify that async code using Unix domain sockets works correctly while blocking TCP/UDP calls. - Prevent DNS resolution during tests to catch hardcoded hostnames or missing mock setup. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. A pytest plugin that blocks or restricts socket calls during tests, preventing unintended network access and DNS resolution while allowing selective allowlisting of hosts or Unix domain sockets. Yes. This is a focused, well-maintained tool with low install friction and no security issues. It solves a real problem—preventing accidental network calls in tests—and integrates cleanly with pytest via CLI flags, config, or fixtures. The MIT license is permissive and the active maintenance (recent release, active repo) makes it reliable for production test suites. ## Install pip install pytest-socket uv add pytest-socket poetry add pytest-socket ## Installing pytest-socket Before you install: Low friction: pure Python wheel with only pytest as a runtime dependency. Actively maintained with a recent release; last commit 2026-08-11 and 342 repository stars indicate ongoing support. License in practice: MIT license (permissive) means you can use, modify, and distribute this plugin freely in commercial and open-source projects with minimal restrictions. Quickstart: pip install pytest-socket # In pytest.ini or setup.cfg: [pytest] addopts = --disable-socket # Or in conftest.py: from pytest_socket import disable_socket def pytest_runtest_setup(): disable_socket() Requires Python 3.10 or greater and pytest 7.0 or greater. Verify before relying: - Whether the plugin works with pytest plugins that also patch socket at module or session scope. - Performance overhead of socket interception across large test suites. - Compatibility with async testing frameworks beyond the documented Unix socket support. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 13.9M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags pytest network isolation, disable socket calls in tests, prevent network access during testing, pytest socket blocking, test network restrictions, pytest DNS blocking, socket call interception, test-isolation, network-mocking [View on SkillFed](https://skillfed.io/packages/pytest-socket) · [View on PyPI](https://pypi.org/project/pytest-socket/)