]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix skipping tests requiring the requests module
authorMichał Kępień <michal@isc.org>
Mon, 14 Mar 2022 07:59:32 +0000 (08:59 +0100)
committerMichał Kępień <michal@isc.org>
Mon, 14 Mar 2022 08:19:03 +0000 (09:19 +0100)
The intended purpose of the @pytest.mark.requests decorator was to cause
Python-based parts of the "statschannel" system test to be skipped if
the requests Python module is not available.  However, both
tests-json.py and tests-xml.py contain a global "import requests"
statement which triggers ImportError exceptions during test
initialization if the requests module is not available.  In other words,
the @pytest.mark.requests decorator serves no useful purpose.

Since all tests in both tests-json.py and tests-xml.py depend on the
requests Python module, employ pytest.importorskip() to ensure the
Python-based parts of the "statschannel" system test are skipped when
the requests module is not available.  Remove all occurrences of the
@pytest.mark.requests decorator (and all associated code) to prevent
confusion.

(cherry picked from commit 704ad2907ff84e84de2f0cfab33ff6ea3d2ea8e4)

bin/tests/system/statschannel/conftest.py
bin/tests/system/statschannel/tests-json.py
bin/tests/system/statschannel/tests-xml.py

index f876f5d56e469c2f2220d1229321554e45262971..363dd7ad1bf8d8c7c92b2c360a6225eb1f1035ea 100644 (file)
@@ -13,26 +13,6 @@ import os
 import pytest
 
 
-def pytest_configure(config):
-    config.addinivalue_line(
-        "markers", "requests: mark tests that need requests to function"
-    )
-
-
-def pytest_collection_modifyitems(config, items):
-    # pylint: disable=unused-argument,unused-import,too-many-branches
-    # pylint: disable=import-outside-toplevel
-    # Test for requests module
-    skip_requests = pytest.mark.skip(
-        reason="need requests module to run")
-    try:
-        import requests  # noqa: F401
-    except ModuleNotFoundError:
-        for item in items:
-            if "requests" in item.keywords:
-                item.add_marker(skip_requests)
-
-
 @pytest.fixture
 def statsport(request):
     # pylint: disable=unused-argument
index 84337a7a8bf3cd67165c5509b2bb7c1448b123b0..373f98d30bc323b690deef8ea8e0c52356ca44db 100755 (executable)
@@ -16,12 +16,12 @@ from datetime import datetime
 import os
 
 import pytest
-import requests
 
 import generic
 
 pytestmark = pytest.mark.skipif(not os.environ.get('HAVEJSONSTATS'),
                                 reason='json-c support disabled in the build')
+requests = pytest.importorskip('requests')
 
 
 # JSON helper functions
@@ -75,27 +75,23 @@ def load_zone_json(zone):
     return name
 
 
-@pytest.mark.requests
 def test_zone_timers_primary_json(statsport):
     generic.test_zone_timers_primary(fetch_zones_json, load_timers_json,
                                      statsip="10.53.0.1", statsport=statsport,
                                      zonedir="ns1")
 
 
-@pytest.mark.requests
 def test_zone_timers_secondary_json(statsport):
     generic.test_zone_timers_secondary(fetch_zones_json, load_timers_json,
                                        statsip="10.53.0.3", statsport=statsport,
                                        zonedir="ns3")
 
 
-@pytest.mark.requests
 def test_zone_with_many_keys_json(statsport):
     generic.test_zone_with_many_keys(fetch_zones_json, load_zone_json,
                                      statsip="10.53.0.2", statsport=statsport)
 
 
-@pytest.mark.requests
 def test_traffic_json(named_port, statsport):
     generic_dnspython = pytest.importorskip('generic_dnspython')
     generic_dnspython.test_traffic(fetch_traffic_json,
index 75edc1a8c4b30c0dbc226f2d72cff2b7e5c9feae..73b6e909f3cd64076e42d688c17d10319c0baaa6 100755 (executable)
@@ -17,12 +17,12 @@ from datetime import datetime
 import os
 
 import pytest
-import requests
 
 import generic
 
 pytestmark = pytest.mark.skipif(not os.environ.get('HAVEXMLSTATS'),
                                 reason='libxml2 support disabled in the build')
+requests = pytest.importorskip('requests')
 
 
 # XML helper functions
@@ -105,27 +105,23 @@ def load_zone_xml(zone):
     return name
 
 
-@pytest.mark.requests
 def test_zone_timers_primary_xml(statsport):
     generic.test_zone_timers_primary(fetch_zones_xml, load_timers_xml,
                                      statsip="10.53.0.1", statsport=statsport,
                                      zonedir="ns1")
 
 
-@pytest.mark.requests
 def test_zone_timers_secondary_xml(statsport):
     generic.test_zone_timers_secondary(fetch_zones_xml, load_timers_xml,
                                        statsip="10.53.0.3", statsport=statsport,
                                        zonedir="ns3")
 
 
-@pytest.mark.requests
 def test_zone_with_many_keys_xml(statsport):
     generic.test_zone_with_many_keys(fetch_zones_xml, load_zone_xml,
                                      statsip="10.53.0.2", statsport=statsport)
 
 
-@pytest.mark.requests
 def test_traffic_xml(named_port, statsport):
     generic_dnspython = pytest.importorskip('generic_dnspython')
     generic_dnspython.test_traffic(fetch_traffic_xml,