conftest.py 497 B

123456789101112131415
  1. import pytest
  2. import urllib3
  3. import urllib
  4. import urllib.request
  5. import socket
  6. # https://realpython.com/pytest-python-testing/
  7. @pytest.fixture(autouse=True)
  8. def disable_network_calls(monkeypatch):
  9. def stunted_get(*args, **kwargs):
  10. raise RuntimeError('Network access not allowed during testing!')
  11. monkeypatch.setattr(urllib.request, 'Request', stunted_get)
  12. monkeypatch.setattr(urllib3.PoolManager, 'request', stunted_get)
  13. monkeypatch.setattr(socket, 'socket', stunted_get)