idlesign / pytest-responsemock

Simplified requests calls mocking for pytest
https://github.com/idlesign/pytest-responsemock
BSD 3-Clause "New" or "Revised" License
27 stars 1 forks source link

ResourceWarning when using response_mock #7

Closed flying-sheep closed 1 year ago

flying-sheep commented 1 year ago

Running my tests with PYTHONTRACEMALLOC=20 shows the following.

This might be a problem with responses itself, but I’m not sure.

  /usr/lib/python3.11/socket.py:777: ResourceWarning: unclosed <socket.socket fd=11, family=2, type=1, proto=0, laddr=('0.0.0.0', 0)>
    self._sock = None

  Object allocated at:
    […]
    File "…/tests/test_cruft.py", line 31
      with response_mock(f"GET https://api.github.com:443/users/scverse-bot -> 200 :{resp}"):
    File "/usr/lib/python3.11/contextlib.py", line 144
      next(self.gen)
    File "…/lib/python3.11/site-packages/responsemock/utils.py", line 67
      with RequestsMock(**kwargs) as mock:
    File "…/lib/python3.11/site-packages/responses/__init__.py", line 957
      self.reset()
    File "…/lib/python3.11/site-packages/responses/__init__.py", line 741
      self._calls.reset()
    File "…/lib/python3.11/site-packages/responses/__init__.py", line 254
      self._calls = []
    File "/usr/lib/python3.11/http/client.py", line 422
      self._close_conn()
    File "/usr/lib/python3.11/http/client.py", line 415
      fp.close()
    File "/usr/lib/python3.11/socket.py", line 777
      self._sock = None
idlesign commented 1 year ago

This might be a problem with responses itself, but I’m not sure.

Yes it seems to be so.

flying-sheep commented 1 year ago

Oof I’m sorry, I apparently didn’t search their bug tracker right. It’s simply https://github.com/getsentry/responses/issues/689