Whole file
miketheman/pytest-socket
The author described this change as “fix: make SocketConnectBlockedError pickleable (#501)”. It counts as a record because the check below fails on the code as it stood at 7bfe8f973 and passes on 2bf8608ad, with nothing else changed between the two runs.
Projectmiketheman/pytest-socket
Fix saved2026-06-30
Sharing licenceMIT · LICENSE
Change size+9 −0
What the code was meant to do, written into the code itself as a save note
fix: make SocketConnectBlockedError pickleable (#501)
The change
| 38 | 38 | *_args: Any, | |
| 39 | 39 | **_kwargs: Any, | |
| 40 | 40 | ) -> None: | |
| 41 | + | self._allowed = allowed | |
| 42 | + | self._host = host | |
| 41 | 43 | allowed_str = ",".join(allowed) | |
| 42 | 44 | msg = ( | |
| 43 | 45 | "A test tried to use socket.socket.connect() " | |
| ⋯ | |||
| 45 | 47 | ) | |
| 46 | 48 | warnings.warn(msg, stacklevel=2) | |
| 47 | 49 | super().__init__(msg) | |
| 50 | + | ||
| 51 | + | def __reduce__(self) -> tuple[Any, tuple[Any, ...]]: | |
| 52 | + | # Reconstruct from the original constructor args so the exception | |
| 53 | + | # survives pickling by multiprocessing test runners (e.g. pytest-xdist, | |
| 54 | + | # Django's `--parallel`). The default `BaseException.__reduce__` would | |
| 55 | + | # replay `self.args` (the formatted message) and miss `host`. | |
| 56 | + | return (self.__class__, (self._allowed, self._host)) | |
| 48 | 57 | ||
| 49 | 58 | ||
| 50 | 59 | def pytest_addoption(parser: pytest.Parser) -> None: | |
The check that tells the two apart
fail→pass·tests/test_socket.py::test_exceptions_are_pickleable[exc1]
Check file tests/test_socket.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it7bfe8f973e565088a97e5c538dfcac70d0c85d61
Broken version dated2026-06-30
Modulepytest_socket.__init__
Units changedSocketConnectBlockedError
Fingerprint5e3eadf0ec31ca97
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.