From 3680763577ece10863a2549773fa117df12e7ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Mon, 14 Mar 2022 08:59:32 +0100 Subject: [PATCH] Simplify skipping tests depending on json-c 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. (cherry picked from commit 0a76f186a5ad4bb22e27c36f2a29ddb9e5398ae7) --- bin/tests/system/rpzextra/conftest.py | 7 ------- bin/tests/system/statschannel/conftest.py | 19 ------------------- bin/tests/system/statschannel/tests-json.py | 15 +++------------ 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/bin/tests/system/rpzextra/conftest.py b/bin/tests/system/rpzextra/conftest.py index 8bbcf25ad7..aa2034fcb0 100644 --- a/bin/tests/system/rpzextra/conftest.py +++ b/bin/tests/system/rpzextra/conftest.py @@ -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) diff --git a/bin/tests/system/statschannel/conftest.py b/bin/tests/system/statschannel/conftest.py index 798bee7300..0a766781fa 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", "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") diff --git a/bin/tests/system/statschannel/tests-json.py b/bin/tests/system/statschannel/tests-json.py index 1f4d6d6e65..84337a7a8b 100755 --- a/bin/tests/system/statschannel/tests-json.py +++ b/bin/tests/system/statschannel/tests-json.py @@ -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,