From: Michał Kępień Date: Mon, 14 Mar 2022 07:59:32 +0000 (+0100) Subject: Fix skipping tests requiring dnspython X-Git-Tag: v9.19.0~67^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=05c97f2329309506060e29c2935739aed6a815dd;p=thirdparty%2Fbind9.git Fix skipping tests requiring dnspython The intended purpose of the @pytest.mark.dnspython{,2} decorators was to cause dnspython-based tests to be skipped if dnspython is not available (or not recent enough). However, a number of system tests employing those decorators contain global "import dns.resolver" statements which trigger ImportError exceptions during test initialization if dnspython is not available. In other words, the @pytest.mark.dnspython{,2} decorators serve no useful purpose. Currently, whenever a Python-based test requires dnspython, that requirement applies to all tests in a given *.py file. Given that, employ global pytest.importorskip() calls to ensure dnspython-based parts of various system tests are skipped when dnspython is not available. Remove all occurrences of the @pytest.mark.dnspython{,2} decorators (and all associated code) to prevent confusion. --- diff --git a/bin/tests/system/checkds/conftest.py b/bin/tests/system/checkds/conftest.py deleted file mode 100644 index 5328ae0177a..00000000000 --- a/bin/tests/system/checkds/conftest.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (C) Internet Systems Consortium, Inc. ("ISC") -# -# SPDX-License-Identifier: MPL-2.0 -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, you can obtain one at https://mozilla.org/MPL/2.0/. -# -# See the COPYRIGHT file distributed with this work for additional -# information regarding copyright ownership. - -import pytest - - -def pytest_configure(config): - config.addinivalue_line( - "markers", "dnspython: mark tests that need dnspython to function" - ) - config.addinivalue_line( - "markers", "dnspython2: mark tests that need dnspython >= 2.0.0" - ) - - -def pytest_collection_modifyitems(config, items): - # pylint: disable=unused-argument,unused-import,too-many-branches - # pylint: disable=import-outside-toplevel - - # Test for dnspython module - skip_dnspython = pytest.mark.skip( - reason="need dnspython module to run") - try: - import dns.query # noqa: F401 - except ModuleNotFoundError: - for item in items: - if "dnspython" in item.keywords: - item.add_marker(skip_dnspython) - - # Test for dnspython >= 2.0.0 module - skip_dnspython2 = pytest.mark.skip( - reason="need dnspython >= 2.0.0 module to run") - try: - from dns.query import udp_with_fallback # noqa: F401 - except ImportError: - for item in items: - if "dnspython2" in item.keywords: - item.add_marker(skip_dnspython2) diff --git a/bin/tests/system/checkds/tests-checkds.py b/bin/tests/system/checkds/tests-checkds.py index a774d43345b..40611e8d05b 100755 --- a/bin/tests/system/checkds/tests-checkds.py +++ b/bin/tests/system/checkds/tests-checkds.py @@ -20,6 +20,8 @@ import time import dns.resolver import pytest +pytest.importorskip('dns', minversion='2.0.0') + def has_signed_apex_nsec(zone, response): has_nsec = False @@ -220,8 +222,6 @@ def wait_for_log(filename, log): assert found -@pytest.mark.dnspython -@pytest.mark.dnspython2 def test_checkds_dspublished(named_port): # We create resolver instances that will be used to send queries. server = dns.resolver.Resolver() @@ -304,8 +304,6 @@ def test_checkds_dspublished(named_port): # TBD: Check with TLS -@pytest.mark.dnspython -@pytest.mark.dnspython2 def test_checkds_dswithdrawn(named_port): # We create resolver instances that will be used to send queries. server = dns.resolver.Resolver() diff --git a/bin/tests/system/rpzextra/conftest.py b/bin/tests/system/rpzextra/conftest.py deleted file mode 100644 index aa2034fcb02..00000000000 --- a/bin/tests/system/rpzextra/conftest.py +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (C) Internet Systems Consortium, Inc. ("ISC") -# -# SPDX-License-Identifier: MPL-2.0 -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, you can obtain one at https://mozilla.org/MPL/2.0/. -# -# See the COPYRIGHT file distributed with this work for additional -# information regarding copyright ownership. - -import pytest - -try: - import dns.resolver # noqa: F401 # pylint: disable=unused-import -except ModuleNotFoundError: - dns_resolver_module_found = False -else: - dns_resolver_module_found = True - - -def pytest_configure(config): - config.addinivalue_line( - "markers", "dnspython: mark tests that need dnspython to function" - ) - - -def pytest_collection_modifyitems(config, items): - # pylint: disable=unused-argument - # Test for dnspython module - if not dns_resolver_module_found: - skip_requests = pytest.mark.skip(reason="need dnspython module to run") - for item in items: - if "dnspython" in item.keywords: - item.add_marker(skip_requests) diff --git a/bin/tests/system/rpzextra/tests-rpz-passthru-logging.py b/bin/tests/system/rpzextra/tests-rpz-passthru-logging.py index 0bd75ebe4d5..4785babfbaf 100755 --- a/bin/tests/system/rpzextra/tests-rpz-passthru-logging.py +++ b/bin/tests/system/rpzextra/tests-rpz-passthru-logging.py @@ -12,11 +12,13 @@ # information regarding copyright ownership. import os + import pytest + +pytest.importorskip('dns') import dns.resolver -# @pytest.mark.dnspython def test_rpz_passthru_logging(named_port): resolver = dns.resolver.Resolver() resolver.nameservers = ['10.53.0.1'] diff --git a/bin/tests/system/shutdown/conftest.py b/bin/tests/system/shutdown/conftest.py deleted file mode 100644 index 04741da104e..00000000000 --- a/bin/tests/system/shutdown/conftest.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (C) Internet Systems Consortium, Inc. ("ISC") -# -# SPDX-License-Identifier: MPL-2.0 -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, you can obtain one at https://mozilla.org/MPL/2.0/. -# -# See the COPYRIGHT file distributed with this work for additional -# information regarding copyright ownership. - -import pytest - - -def pytest_configure(config): - config.addinivalue_line( - "markers", "dnspython: mark tests that need dnspython to function" - ) - - -def pytest_collection_modifyitems(config, items): - # pylint: disable=unused-argument,unused-import,too-many-branches - # pylint: disable=import-outside-toplevel - - # Test for dnspython module - skip_dnspython = pytest.mark.skip( - reason="need dnspython module to run") - try: - import dns.query # noqa: F401 - except ModuleNotFoundError: - for item in items: - if "dnspython" in item.keywords: - item.add_marker(skip_dnspython) diff --git a/bin/tests/system/shutdown/tests-shutdown.py b/bin/tests/system/shutdown/tests-shutdown.py index d8c2b1f6629..9ed222bb1a7 100755 --- a/bin/tests/system/shutdown/tests-shutdown.py +++ b/bin/tests/system/shutdown/tests-shutdown.py @@ -22,6 +22,8 @@ import time import dns.resolver import pytest +pytest.importorskip('dns') + def do_work(named_proc, resolver, rndc_cmd, kill_method, n_workers, n_queries): """Creates a number of A queries to run in parallel @@ -126,7 +128,6 @@ def do_work(named_proc, resolver, rndc_cmd, kill_method, n_workers, n_queries): assert ret_code == 0 -@pytest.mark.dnspython def test_named_shutdown(named_port, control_port): # pylint: disable-msg=too-many-locals cfg_dir = os.path.join(os.getcwd(), "resolver") diff --git a/bin/tests/system/tcp/conftest.py b/bin/tests/system/tcp/conftest.py deleted file mode 100644 index 4789c92d90b..00000000000 --- a/bin/tests/system/tcp/conftest.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (C) Internet Systems Consortium, Inc. ("ISC") -# -# SPDX-License-Identifier: MPL-2.0 -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, you can obtain one at https://mozilla.org/MPL/2.0/. -# -# See the COPYRIGHT file distributed with this work for additional -# information regarding copyright ownership. - -import pytest - - -def pytest_configure(config): - config.addinivalue_line( - "markers", "dnspython: mark tests that need dnspython to function" - ) - config.addinivalue_line( - "markers", "dnspython2: mark tests that need dnspython >= 2.0.0" - ) - - -def pytest_collection_modifyitems(config, items): - # pylint: disable=unused-argument,unused-import,too-many-branches - # pylint: disable=import-outside-toplevel - - # Test for dnspython module - skip_dnspython = pytest.mark.skip( - reason="need dnspython module to run") - try: - import dns.query # noqa: F401 - except ModuleNotFoundError: - for item in items: - if "dnspython" in item.keywords: - item.add_marker(skip_dnspython) - - # Test for dnspython >= 2.0.0 module - skip_dnspython2 = pytest.mark.skip( - reason="need dnspython >= 2.0.0 module to run") - try: - from dns.query import send_tcp # noqa: F401 - except ImportError: - for item in items: - if "dnspython2" in item.keywords: - item.add_marker(skip_dnspython2) diff --git a/bin/tests/system/tcp/tests-tcp.py b/bin/tests/system/tcp/tests-tcp.py index 3e6fadf8902..7a12dc2be2d 100644 --- a/bin/tests/system/tcp/tests-tcp.py +++ b/bin/tests/system/tcp/tests-tcp.py @@ -19,6 +19,9 @@ import time import pytest +pytest.importorskip('dns', minversion='2.0.0') + + TIMEOUT = 10 @@ -39,8 +42,6 @@ def create_socket(host, port): return sock -@pytest.mark.dnspython -@pytest.mark.dnspython2 def test_tcp_garbage(named_port): import dns.query @@ -66,8 +67,6 @@ def test_tcp_garbage(named_port): raise EOFError from e -@pytest.mark.dnspython -@pytest.mark.dnspython2 def test_tcp_garbage_response(named_port): import dns.query import dns.message diff --git a/bin/tests/system/timeouts/conftest.py b/bin/tests/system/timeouts/conftest.py index 2639774c1e0..3a4375232d3 100644 --- a/bin/tests/system/timeouts/conftest.py +++ b/bin/tests/system/timeouts/conftest.py @@ -14,12 +14,6 @@ import pytest def pytest_configure(config): - config.addinivalue_line( - "markers", "dnspython: mark tests that need dnspython to function" - ) - config.addinivalue_line( - "markers", "dnspython2: mark tests that need dnspython >= 2.0.0" - ) config.addinivalue_line( "markers", "long: mark tests that take a long time to run" ) @@ -28,27 +22,6 @@ def pytest_configure(config): def pytest_collection_modifyitems(config, items): # pylint: disable=unused-argument,unused-import,too-many-branches # pylint: disable=import-outside-toplevel - - # Test for dnspython module - skip_dnspython = pytest.mark.skip( - reason="need dnspython module to run") - try: - import dns.query # noqa: F401 - except ModuleNotFoundError: - for item in items: - if "dnspython" in item.keywords: - item.add_marker(skip_dnspython) - - # Test for dnspython >= 2.0.0 module - skip_dnspython2 = pytest.mark.skip( - reason="need dnspython >= 2.0.0 module to run") - try: - from dns.query import send_tcp # noqa: F401 - except ImportError: - for item in items: - if "dnspython2" in item.keywords: - item.add_marker(skip_dnspython2) - skip_long_tests = pytest.mark.skip( reason="need CI_ENABLE_ALL_TESTS environment variable") if not os.environ.get("CI_ENABLE_ALL_TESTS"): diff --git a/bin/tests/system/timeouts/tests-tcp.py b/bin/tests/system/timeouts/tests-tcp.py index 8481a3e9b32..a17380af586 100644 --- a/bin/tests/system/timeouts/tests-tcp.py +++ b/bin/tests/system/timeouts/tests-tcp.py @@ -18,6 +18,9 @@ import time import pytest +pytest.importorskip('dns', minversion='2.0.0') + + TIMEOUT = 10 @@ -32,8 +35,6 @@ def timeout(): return time.time() + TIMEOUT -@pytest.mark.dnspython -@pytest.mark.dnspython2 def test_initial_timeout(named_port): # # The initial timeout is 2.5 seconds, so this should timeout @@ -55,8 +56,6 @@ def test_initial_timeout(named_port): raise EOFError from e -@pytest.mark.dnspython -@pytest.mark.dnspython2 def test_idle_timeout(named_port): # # The idle timeout is 5 seconds, so the third message should fail @@ -87,8 +86,6 @@ def test_idle_timeout(named_port): raise EOFError from e -@pytest.mark.dnspython -@pytest.mark.dnspython2 def test_keepalive_timeout(named_port): # # Keepalive is 7 seconds, so the third message should succeed. @@ -118,8 +115,6 @@ def test_keepalive_timeout(named_port): (response, rtime) = dns.query.receive_tcp(sock, timeout()) -@pytest.mark.dnspython -@pytest.mark.dnspython2 def test_pipelining_timeout(named_port): # # The pipelining should only timeout after the last message is received @@ -156,8 +151,6 @@ def test_pipelining_timeout(named_port): raise EOFError from e -@pytest.mark.dnspython -@pytest.mark.dnspython2 def test_long_axfr(named_port): # # The timers should not fire during AXFR, thus the connection should not @@ -192,8 +185,6 @@ def test_long_axfr(named_port): assert soa is not None -@pytest.mark.dnspython -@pytest.mark.dnspython2 def test_send_timeout(named_port): import dns.query @@ -222,8 +213,6 @@ def test_send_timeout(named_port): raise EOFError from e -@pytest.mark.dnspython -@pytest.mark.dnspython2 @pytest.mark.long def test_max_transfer_idle_out(named_port): import dns.query @@ -259,8 +248,6 @@ def test_max_transfer_idle_out(named_port): assert soa is None -@pytest.mark.dnspython -@pytest.mark.dnspython2 @pytest.mark.long def test_max_transfer_time_out(named_port): import dns.query