From: Stefano Rivera <stefanor@debian.org>
Date: Mon, 6 Nov 2023 14:23:17 +0200
Subject: Tests: Use a mark for requires_network

As an alternative to #3162, we can add a requires_network pytest mark,
rather than relying on automatic network detection.

The use-case here is Debian package builds without Intenet access. We
have environments where Internet access is available, and environments
where it isn't. We'd like to be able to specify our expectation to the
test-suite.

Forwarded: https://github.com/urllib3/urllib3/pull/3166
---
 pyproject.toml   |  5 ++++-
 test/__init__.py | 18 +++++++++++++++---
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index 2b33cc9..bd75da3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -81,7 +81,10 @@ include = [
 [tool.pytest.ini_options]
 xfail_strict = true
 python_classes = ["Test", "*TestCase"]
-markers = ["limit_memory"]
+markers = [
+    "limit_memory: Limit memory with memray",
+    "requires_network: This test needs access to the Internet",
+]
 log_level = "DEBUG"
 filterwarnings = [
     "error",
diff --git a/test/__init__.py b/test/__init__.py
index 7f75ad2..86678b4 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -210,14 +210,26 @@ def requires_network() -> typing.Callable[[_TestFuncT], _TestFuncT]:
             else:
                 raise
 
+    def _decorator_requires_internet(
+        decorator: typing.Callable[[_TestFuncT], _TestFuncT]
+    ) -> typing.Callable[[_TestFuncT], _TestFuncT]:
+        """Mark a decorator with the "requires_internet" mark"""
+
+        def wrapper(f: _TestFuncT) -> typing.Any:
+            return pytest.mark.requires_network(decorator(f))
+
+        return wrapper
+
     global _requires_network_has_route
 
     if _requires_network_has_route is None:
         _requires_network_has_route = _has_route()
 
-    return pytest.mark.skipif(
-        not _requires_network_has_route,
-        reason="Can't run the test because the network is unreachable",
+    return _decorator_requires_internet(
+        pytest.mark.skipif(
+            not _requires_network_has_route,
+            reason="Can't run the test because the network is unreachable",
+        )
     )
 
 
