kiwicom / pytest-recording

A pytest plugin that allows recording network interactions via VCR.py
MIT License
445 stars 35 forks source link

[BUG] tests/test_blocking_network.py::test_block_network_with_allowed_hosts fail with no network (does not block DNS requests?)) #131

Open mgorny opened 1 year ago

mgorny commented 1 year ago

Describe the bug When running the test suite in an environment without Internet access, I'm getting the following test failures:

FAILED tests/test_blocking_network.py::test_block_network_with_allowed_hosts[block_marker] - AssertionError: assert {'errors': 0,...pped': 0, ...} == {'errors': 0,...pped': 0, ...}
FAILED tests/test_blocking_network.py::test_block_network_with_allowed_hosts[block_cmd] - AssertionError: assert {'errors': 0,...pped': 0, ...} == {'errors': 0,...pped': 0, ...}
FAILED tests/test_blocking_network.py::test_block_network_with_allowed_hosts[vcr_cfg] - AssertionError: assert {'errors': 0,...pped': 0, ...} == {'errors': 0,...pped': 0, ...}

If I'm reading the output right, even though the requests were supposed to be blocked, requests attempts to resolve example.com and fails with NameResolutionError.

Full log: test-output.txt

To Reproduce Steps to reproduce the behavior:

  1. Run tox -e py311 (or alike) to prepare the test env
  2. sudo unshare -n
  3. ifconfig lo up
  4. su - <regularuser>
  5. cd <pytest-recording-checkout>
  6. . .tox/py311/bin/activate
  7. python -m pytest

Expected behavior Tests passing (i.e. no DNS requests should be made if network access is blocked).

Environment (please complete the following information):

Additional context n/a