]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Simplify skipping tests depending on libxml2
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)
All tests in bin/tests/system/statschannel/tests-xml.py require libxml2
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-xml.py if libxml2 support is not compiled in.

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

(cherry picked from commit 286b57c7f165c441170bc3aa6f7faa097161b7ee)

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

index 0a766781fa56638bf5f00057e3e3bd7aca1b2247..f876f5d56e469c2f2220d1229321554e45262971 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", "xml: mark tests that need xml.etree to function"
-    )
 
 
 def pytest_collection_modifyitems(config, items):
@@ -34,22 +31,6 @@ def pytest_collection_modifyitems(config, items):
         for item in items:
             if "requests" in item.keywords:
                 item.add_marker(skip_requests)
-    # Test for xml module
-    skip_xml = pytest.mark.skip(
-        reason="need xml module to run")
-    try:
-        import xml.etree.ElementTree  # noqa: F401
-    except ModuleNotFoundError:
-        for item in items:
-            if "xml" in item.keywords:
-                item.add_marker(skip_xml)
-    # Test if XML statistics channel was enabled
-    no_xmlstats = pytest.mark.skip(
-        reason="need XML statistics to be enabled")
-    if os.getenv("HAVEXMLSTATS") is None:
-        for item in items:
-            if "xml" in item.keywords:
-                item.add_marker(no_xmlstats)
 
 
 @pytest.fixture
index efd66a5b684b9840c4c80807c2bac67f75cc8c66..75edc1a8c4b30c0dbc226f2d72cff2b7e5c9feae 100755 (executable)
@@ -21,6 +21,9 @@ import requests
 
 import generic
 
+pytestmark = pytest.mark.skipif(not os.environ.get('HAVEXMLSTATS'),
+                                reason='libxml2 support disabled in the build')
+
 
 # XML helper functions
 def fetch_zones_xml(statsip, statsport):
@@ -102,39 +105,27 @@ def load_zone_xml(zone):
     return name
 
 
-@pytest.mark.xml
 @pytest.mark.requests
-@pytest.mark.skipif(os.getenv("HAVEXMLSTATS", "unset") != "1",
-                    reason="XML not configured")
 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.xml
 @pytest.mark.requests
-@pytest.mark.skipif(os.getenv("HAVEXMLSTATS", "unset") != "1",
-                    reason="XML not configured")
 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.xml
 @pytest.mark.requests
-@pytest.mark.skipif(os.getenv("HAVEXMLSTATS", "unset") != "1",
-                    reason="XML not configured")
 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.xml
 @pytest.mark.requests
-@pytest.mark.skipif(os.getenv("HAVEXMLSTATS", "unset") != "1",
-                    reason="XML not configured")
 def test_traffic_xml(named_port, statsport):
     generic_dnspython = pytest.importorskip('generic_dnspython')
     generic_dnspython.test_traffic(fetch_traffic_xml,