diff --git a/src/pytestskipmarkers/utils/markers.py b/src/pytestskipmarkers/utils/markers.py index fbc0d1a..45b02a3 100644 --- a/src/pytestskipmarkers/utils/markers.py +++ b/src/pytestskipmarkers/utils/markers.py @@ -137,6 +137,9 @@ def skip_if_no_remote_network() -> Optional[str]: str: The reason for the skip. None: Should not be skipped. """ + if os.environ.get("NO_INTERNET"): + return "Environment variable NO_INTERNET is set" + # We are using the google.com DNS records as numerical IPs to avoid # DNS look ups which could greatly slow down this check has_remote_network = False diff --git a/tests/unit/utils/markers/test_skip_if_no_remote_network.py b/tests/unit/utils/markers/test_skip_if_no_remote_network.py index fffdd14..db72ff7 100644 --- a/tests/unit/utils/markers/test_skip_if_no_remote_network.py +++ b/tests/unit/utils/markers/test_skip_if_no_remote_network.py @@ -4,6 +4,7 @@ """ Test the "skip_if_no_remote_network" marker helper. """ +import os from unittest import mock import pytestskipmarkers.utils.markers as markers @@ -22,3 +23,12 @@ def test_no_remote_network(): skip_reason = markers.skip_if_no_remote_network() assert skip_reason is not None assert skip_reason == "No internet network connection was detected" + + +def test_remote_network_with_no_internet(): + environ = os.environ.copy() + environ["NO_INTERNET"] = "1" + with mock.patch("os.environ", return_value=environ): + skip_reason = markers.skip_if_no_remote_network() + assert skip_reason is not None + assert skip_reason == "Environment variable NO_INTERNET is set"