Usage
The intended use is for making sure your unit tests don’t make network connections. Activate sockfilter with a predicate like:
# only allow http connections to localhost
def socket_address_allowed(address):
return (address.host in ['localhost', '127.0.0.1'] and
address.port == 80)
sockfilter.enable(socket_address_allowed)
Any subsequent attempts to open a connection at an address not satisfying the predicate will raise sockfilter.SockFilterError.
with_sockfiltering decorator
from sockfilter import with_sockfiltering
@with_sockfiltering(socket_address_allowed)
def test_foo():
foo()
sockfiltering context manager
from sockfilter import sockfiltering
def test_foo():
with sockfiltering(socket_address_allowed):
foo()
enable and disable
import sockfilter
from unittest import TestCase
class FooTest(TestCase):
def setUp(self):
sockfilter.enable(socket_address_allowed)
def tearDown(self):
sockfilter.disable()
def test_foo(self):
foo()
Under the hood
Sockfilter works by monkey-patching Python’s socket library, inspired by HTTPretty.
Metadata
Release files for sockfilter 1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sockfilter-1.4.tar.gz | 5.5 kB | Without provenance | Details for sockfilter-1.4.tar.gz |
Release files / sockfilter-1.4.tar.gz
| Download URL | sockfilter-1.4.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0aef68d7d76a5842d32174a8a20c5e480f91ed015d535a57d2192b12e152b05a
|
|
BLAKE2b-256 checksum How to use checksums |
0f99e6a1f75d6d6069c96cbedffb23b11f673492c3b4daebf2367aa52bc79b5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for sockfilter 1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.