]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix skipping tests requiring dnspython
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)
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.

(cherry picked from commit 05c97f2329309506060e29c2935739aed6a815dd)

bin/tests/system/checkds/conftest.py [deleted file]
bin/tests/system/checkds/tests-checkds.py
bin/tests/system/shutdown/conftest.py [deleted file]
bin/tests/system/shutdown/tests-shutdown.py
bin/tests/system/timeouts/conftest.py
bin/tests/system/timeouts/tests-tcp.py

diff --git a/bin/tests/system/checkds/conftest.py b/bin/tests/system/checkds/conftest.py
deleted file mode 100644 (file)
index 5328ae0..0000000
+++ /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)
index f61138b1302ffa38f0c0e3f14de8fe333d03a654..afd77faa08520f284d2818cce9105847bf3e0930 100755 (executable)
@@ -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()
@@ -302,8 +302,6 @@ def test_checkds_dspublished(named_port):
     # TBD: Check with TSIG
 
 
-@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/shutdown/conftest.py b/bin/tests/system/shutdown/conftest.py
deleted file mode 100644 (file)
index 04741da..0000000
+++ /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)
index 917c35593cd585a251a439d5150f323ae13cecbc..dd6b62348fb58aabaf07cc555cabea25a0caf6be 100755 (executable)
@@ -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")
index 2639774c1e0755064f493c328536ab39b30d8c6a..3a4375232d3b5196d22937b3cbc5b23980f7b8fa 100644 (file)
@@ -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"):
index 8481a3e9b32478bf7ed603a0ca5139875ed356e5..a17380af586ae0ba2d6e9f6864b8c30b6434625b 100644 (file)
@@ -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