]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Simplify skipping tests depending on json-c
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 07:59:32 +0000 (08:59 +0100)
All tests in bin/tests/system/statschannel/tests-json.py require json-c
support to be enabled in BIND 9 at build-time.  Instead of applying the
same pytest.mark.skipif() decorator to every test in that file, set the
'pytestmark' global accordingly in order to immediately skip all tests
in tests-json.py if json-c support is not compiled in.

Remove all occurrences of the @pytest.mark.json decorator (and all
associated code) from the "statschannel" system test as the json module
is a part of the Python standard library since Python 2.6 (so checking
whether it is available is redundant) and checking for json-c support in
the tested BIND 9 build is already handled by setting the 'pytestmark'
global accordingly.

Also remove a related excerpt from bin/tests/system/rpzextra/conftest.py
as it is a copy-paste artifact that serves no purpose in the "rpzextra"
system test.

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

index 8bbcf25ad7846f64387e9bed90b928ed427b9eb7..aa2034fcb029250718b9b6a4004d78b4af1dfb02 100644 (file)
@@ -9,7 +9,6 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-import os
 import pytest
 
 try:
@@ -34,9 +33,3 @@ def pytest_collection_modifyitems(config, items):
         for item in items:
             if "dnspython" in item.keywords:
                 item.add_marker(skip_requests)
-    # Test if JSON statistics channel was enabled
-    no_jsonstats = pytest.mark.skip(reason="need JSON statistics to be enabled")
-    if os.getenv("HAVEJSONSTATS") is None:
-        for item in items:
-            if "json" in item.keywords:
-                item.add_marker(no_jsonstats)
index 798bee73007acb0e792cda5174f795a91169889d..0a766781fa56638bf5f00057e3e3bd7aca1b2247 100644 (file)
@@ -17,9 +17,6 @@ def pytest_configure(config):
     config.addinivalue_line(
         "markers", "requests: mark tests that need requests to function"
     )
-    config.addinivalue_line(
-        "markers", "json: mark tests that need json to function"
-    )
     config.addinivalue_line(
         "markers", "xml: mark tests that need xml.etree to function"
     )
@@ -37,15 +34,6 @@ def pytest_collection_modifyitems(config, items):
         for item in items:
             if "requests" in item.keywords:
                 item.add_marker(skip_requests)
-    # Test for json module
-    skip_json = pytest.mark.skip(
-        reason="need json module to run")
-    try:
-        import json  # noqa: F401
-    except ModuleNotFoundError:
-        for item in items:
-            if "json" in item.keywords:
-                item.add_marker(skip_json)
     # Test for xml module
     skip_xml = pytest.mark.skip(
         reason="need xml module to run")
@@ -55,13 +43,6 @@ def pytest_collection_modifyitems(config, items):
         for item in items:
             if "xml" in item.keywords:
                 item.add_marker(skip_xml)
-    # Test if JSON statistics channel was enabled
-    no_jsonstats = pytest.mark.skip(
-        reason="need JSON statistics to be enabled")
-    if os.getenv("HAVEJSONSTATS") is None:
-        for item in items:
-            if "json" in item.keywords:
-                item.add_marker(no_jsonstats)
     # Test if XML statistics channel was enabled
     no_xmlstats = pytest.mark.skip(
         reason="need XML statistics to be enabled")
index 1f4d6d6e6508ac7fcaba15a4592237a7ec56b763..84337a7a8bf3cd67165c5509b2bb7c1448b123b0 100755 (executable)
@@ -20,6 +20,9 @@ import requests
 
 import generic
 
+pytestmark = pytest.mark.skipif(not os.environ.get('HAVEJSONSTATS'),
+                                reason='json-c support disabled in the build')
+
 
 # JSON helper functions
 def fetch_zones_json(statsip, statsport):
@@ -72,39 +75,27 @@ def load_zone_json(zone):
     return name
 
 
-@pytest.mark.json
 @pytest.mark.requests
-@pytest.mark.skipif(os.getenv("HAVEJSONSTATS", "unset") != "1",
-                    reason="JSON not configured")
 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.json
 @pytest.mark.requests
-@pytest.mark.skipif(os.getenv("HAVEJSONSTATS", "unset") != "1",
-                    reason="JSON not configured")
 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.json
 @pytest.mark.requests
-@pytest.mark.skipif(os.getenv("HAVEJSONSTATS", "unset") != "1",
-                    reason="JSON not configured")
 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.json
 @pytest.mark.requests
-@pytest.mark.skipif(os.getenv("HAVEJSONSTATS", "unset") != "1",
-                    reason="JSON not configured")
 def test_traffic_json(named_port, statsport):
     generic_dnspython = pytest.importorskip('generic_dnspython')
     generic_dnspython.test_traffic(fetch_traffic_json,