Skip to content

Conversation

jacebrowning
Copy link

@jacebrowning jacebrowning commented Oct 19, 2023

Using the library with a multiprocessing test runner (e.g. Django's manage.py test --parallel) results in the socket exceptions raising a TypeError during deserialization. I propose making the exceptions pickealable by building the custom exception message before constructing each class.

Before:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/test_project/.venv/lib/python3.9/site-packages/django/test/runner.py", line 347, in _run_subsuite
    result = runner.run(subsuite)
  File "/test_project/.venv/lib/python3.9/site-packages/django/test/runner.py", line 294, in run
    test(result)
  File "/usr/local/lib/python3.9/unittest/suite.py", line 84, in __call__
    return self.run(*args, **kwds)
  File "/usr/local/lib/python3.9/unittest/suite.py", line 122, in run
    test(result)

  ...

  File "/test_project/.venv/lib/python3.9/site-packages/django/test/runner.py", line 235, in addError
    self.check_picklable(test, err)
  File "/test_project/.venv/lib/python3.9/site-packages/django/test/runner.py", line 168, in check_picklable
    self._confirm_picklable(err)
  File "/test_project/.venv/lib/python3.9/site-packages/django/test/runner.py", line 142, in _confirm_picklable
    pickle.loads(pickle.dumps(obj))
  File "/test_project/.venv/lib/python3.9/site-packages/tblib/pickling_support.py", line 26, in unpickle_exception
    inst = func(*args)

TypeError: __init__() missing 1 required positional argument: 'host'

After:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/local/lib/python3.9/unittest/case.py", line 592, in run
    self._callTestMethod(testMethod)
  File "/usr/local/lib/python3.9/unittest/case.py", line 550, in _callTestMethod
    method()
  File "/usr/local/lib/python3.9/unittest/mock.py", line 1336, in patched
    return func(*newargs, **newkeywargs)
  File "/test_project/test_module.py", line 123, in test_function
    response = client.post(

  ...

  File "/test_project/.venv/lib/python3.9/site-packages/pytest_socket.py", line 246, in guarded_connect
    raise SocketConnectBlockedError(message)

pytest_socket.SocketConnectBlockedError: A test tried to use socket.socket.connect()
  with host "192.0.80.239" (allowed: "0.0.0.0,127.0.0.1").

Copy link

Code Climate has analyzed commit 48aa02a and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3

View more on Code Climate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant