{"repo":"miketheman/pytest-socket","free":true,"listed":false,"github":"https://github.com/miketheman/pytest-socket","clone":"git clone https://github.com/miketheman/pytest-socket.git","description":"Pytest Plugin to disable socket calls during tests","language":"Python","stars":342,"topics":["pytest-plugin","socket","python","testing","testing-tools"],"license":"MIT","category":"dev-tools","readme_excerpt":"pytest-socket A plugin to use with Pytest to disable or restrict socket calls during tests to ensure network calls are prevented. --- Features - Disables all network calls flowing through Python's socket interface, including DNS resolution. - Restricts connections to an allow-list of hosts, IP addresses, or CIDR network ranges. - Allows Unix domain sockets selectively, for example when testing async code. - Applies globally via CLI flags, or per-test via fixtures and markers. Requirements - Pytest 7.0 or greater - Python 3.10 or greater Installation You can install pytest-socket via pip from PyPI: or add to your pyproject.toml for uv: Usage Run pytest --disable-socket , tests should fail on any access to socket or libraries using socket with a SocketBlockedError . To add this flag as the default behavior, add this section to your pytest.ini : or add this to your setup.cfg : or update your conftest.py to include: If you exceptionally want to enable socket for one particular execution pass --force-enable-socket . It takes precedence over --disable-socket . To enable Unix sockets during the test run (e.g. for async), add this option: To enable specific tests use of socket , pass in the fixture to the test or use a marker: To allow only specific hosts per-test: or for whole test run Entries may be hostnames, IP addresses, or CIDR network ranges such as 192.168.0.0/24 . Frequently Asked Questions Q: Why is network access disabled in some of my tests but not others? A: pytest's def","default_branch":null,"files":null,"tree":[],"storefront":"/r/miketheman","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/miketheman/pytest-socket/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}