From: Michał Kępień Date: Mon, 14 Mar 2022 07:59:32 +0000 (+0100) Subject: Simplify skipping tests depending on libxml2 X-Git-Tag: v9.19.0~67^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=286b57c7f165c441170bc3aa6f7faa097161b7ee;p=thirdparty%2Fbind9.git Simplify skipping tests depending on libxml2 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. --- diff --git a/bin/tests/system/statschannel/conftest.py b/bin/tests/system/statschannel/conftest.py index 0a766781fa5..f876f5d56e4 100644 --- a/bin/tests/system/statschannel/conftest.py +++ b/bin/tests/system/statschannel/conftest.py @@ -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 diff --git a/bin/tests/system/statschannel/tests-xml.py b/bin/tests/system/statschannel/tests-xml.py index efd66a5b684..75edc1a8c4b 100755 --- a/bin/tests/system/statschannel/tests-xml.py +++ b/bin/tests/system/statschannel/tests-xml.py @@ -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,