Skip to content

Commit 098a0e8

Browse files
committed
Allow skipping test cases that need Internet access
Mark test cases that need Internet access and allow skipping them by setting the environment variable `NO_INTERNET`. Forwarded: saltstack#16 Signed-off-by: Benjamin Drung <[email protected]>
1 parent 8ee98c2 commit 098a0e8

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/pytestskipmarkers/downgraded/utils/markers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def skip_if_no_remote_network() -> Optional[str]:
137137
str: The reason for the skip.
138138
None: Should not be skipped.
139139
"""
140+
if os.environ.get('NO_INTERNET'):
141+
return 'Environment variable NO_INTERNET is set'
140142
has_remote_network = False
141143
for addr in (
142144
'172.217.17.14',

src/pytestskipmarkers/utils/markers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ def skip_if_no_remote_network() -> Optional[str]:
137137
str: The reason for the skip.
138138
None: Should not be skipped.
139139
"""
140+
if os.environ.get("NO_INTERNET"):
141+
return "Environment variable NO_INTERNET is set"
142+
140143
# We are using the google.com DNS records as numerical IPs to avoid
141144
# DNS look ups which could greatly slow down this check
142145
has_remote_network = False

tests/unit/utils/markers/test_skip_if_no_remote_network.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
Test the "skip_if_no_remote_network" marker helper.
66
"""
7+
import os
78
from unittest import mock
89

910
import pytestskipmarkers.utils.markers as markers
@@ -22,3 +23,12 @@ def test_no_remote_network():
2223
skip_reason = markers.skip_if_no_remote_network()
2324
assert skip_reason is not None
2425
assert skip_reason == "No internet network connection was detected"
26+
27+
28+
def test_remote_network_with_no_internet():
29+
environ = os.environ.copy()
30+
environ["NO_INTERNET"] = "1"
31+
with mock.patch("os.environ", return_value=environ):
32+
skip_reason = markers.skip_if_no_remote_network()
33+
assert skip_reason is not None
34+
assert skip_reason == "Environment variable NO_INTERNET is set"

0 commit comments

Comments
 (0)