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.

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

3838 *_args: Any,
3939 **_kwargs: Any,
4040 ) -> None:
41+ self._allowed = allowed
42+ self._host = host
4143 allowed_str = ",".join(allowed)
4244 msg = (
4345 "A test tried to use socket.socket.connect() "
4547 )
4648 warnings.warn(msg, stacklevel=2)
4749 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))
4857
4958
5059 def pytest_addoption(parser: pytest.Parser) -> None:

The check that tells the two apart

failpass·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.