mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
Rework skipping long tests
The ability to conveniently mark tests which should only be run when the CI_ENABLE_ALL_TESTS environment variable is set seems to be useful on a general level and therefore it should not be limited to the "timeouts" system test, where it is currently used. pytest documentation [1] suggests to reuse commonly used test markers by putting them all in a single Python module which then has to be imported by test files that want to use the markers defined therein. Follow that advice by creating a new bin/tests/system/pytest_custom_markers.py Python module containing the relevant marker definitions. Note that "import pytest_custom_markers" works from a test-specific subdirectory because pytest modifies sys.path so that it contains the paths to all parent directories containing a conftest.py file (and bin/tests/system/ is one). PyLint does not like that, though, so add a relevant PyLint suppression. The above changes make bin/tests/system/timeouts/conftest.py redundant, so remove it. [1] https://docs.pytest.org/en/7.0.x/how-to/skipping.html#id1
This commit is contained in:
20
bin/tests/system/pytest_custom_markers.py
Normal file
20
bin/tests/system/pytest_custom_markers.py
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
# 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 os
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
long_test = pytest.mark.skipif(not os.environ.get('CI_ENABLE_ALL_TESTS'),
|
||||
reason='CI_ENABLE_ALL_TESTS not set')
|
@@ -111,7 +111,7 @@ if [ "${srcdir}" != "${builddir}" ]; then
|
||||
cp -a "${srcdir}/common" "${builddir}"
|
||||
fi
|
||||
# Some tests require additional files to work for out-of-tree test runs.
|
||||
for file in ckdnsrps.sh conftest.py digcomp.pl ditch.pl fromhex.pl kasp.sh packet.pl start.pl stop.pl testcrypto.sh; do
|
||||
for file in ckdnsrps.sh conftest.py digcomp.pl ditch.pl fromhex.pl kasp.sh packet.pl pytest_custom_markers.py start.pl stop.pl testcrypto.sh; do
|
||||
if [ ! -r "${file}" ]; then
|
||||
cp -a "${srcdir}/${file}" "${builddir}"
|
||||
fi
|
||||
|
@@ -1,30 +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 os
|
||||
import pytest
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
config.addinivalue_line(
|
||||
"markers", "long: mark tests that take a long time to run"
|
||||
)
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
# pylint: disable=unused-argument,unused-import,too-many-branches
|
||||
# pylint: disable=import-outside-toplevel
|
||||
skip_long_tests = pytest.mark.skip(
|
||||
reason="need CI_ENABLE_ALL_TESTS environment variable")
|
||||
if not os.environ.get("CI_ENABLE_ALL_TESTS"):
|
||||
for item in items:
|
||||
if "long" in item.keywords:
|
||||
item.add_marker(skip_long_tests)
|
@@ -26,6 +26,8 @@ import dns.query
|
||||
import dns.rdataclass
|
||||
import dns.rdatatype
|
||||
|
||||
import pytest_custom_markers # pylint: disable=import-error
|
||||
|
||||
|
||||
TIMEOUT = 10
|
||||
|
||||
@@ -204,7 +206,7 @@ def test_send_timeout(named_port):
|
||||
raise EOFError from e
|
||||
|
||||
|
||||
@pytest.mark.long
|
||||
@pytest_custom_markers.long_test
|
||||
def test_max_transfer_idle_out(named_port):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(("10.53.0.1", named_port))
|
||||
@@ -235,7 +237,7 @@ def test_max_transfer_idle_out(named_port):
|
||||
assert soa is None
|
||||
|
||||
|
||||
@pytest.mark.long
|
||||
@pytest_custom_markers.long_test
|
||||
def test_max_transfer_time_out(named_port):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(("10.53.0.1", named_port))
|
||||
|
Reference in New Issue
Block a user