Skip to content

Commit

Permalink
Allow skipping test cases that need Internet access
Browse files Browse the repository at this point in the history
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 <bdrung@debian.org>
  • Loading branch information
bdrung committed Apr 15, 2022
1 parent 8ee98c2 commit 12507f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/pytestskipmarkers/utils/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/utils/markers/test_skip_if_no_remote_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

0 comments on commit 12507f9

Please sign in to comment.