From: Tom Krizek Date: Thu, 1 Dec 2022 14:21:22 +0000 (+0100) Subject: Use feature-test feature detection in pytests X-Git-Tag: v9.19.8~23^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9730ac4c5691c36d58c06deec1762a4831b268c5;p=thirdparty%2Fbind9.git Use feature-test feature detection in pytests Avoid using the environment variables for feature detection and use the feature-test utility instead. Remove the obsolete environment variables from conf.sh, since they're no longer used anywhere. --- diff --git a/bin/tests/system/conf.sh.in b/bin/tests/system/conf.sh.in index a41ac10b631..d6c76ea6f12 100644 --- a/bin/tests/system/conf.sh.in +++ b/bin/tests/system/conf.sh.in @@ -113,18 +113,3 @@ export PERL=$(command -v "@PERL@") export PYTHON=$(command -v "@PYTHON@" || true) export PYTEST=@PYTEST@ - -# -# Determine if we support various optional features. -# -export LIBXML2_LIBS="@LIBXML2_LIBS@" -export HAVEXMLSTATS=${LIBXML2_LIBS:+1} -export JSON_C_LIBS="@JSON_C_LIBS@" -export HAVEJSONSTATS=${JSON_C_LIBS:+1} -export MAXMINDDB_LIBS="@MAXMINDDB_LIBS@" -export HAVEGEOIP2=${MAXMINDDB_LIBS:+1} -export ZLIB_LIBS="@ZLIB_LIBS@" -export HAVEZLIB=${ZLIB_LIBS:+1} -export LMDB_LIBS="@LMDB_LIBS@" -export NZD=${LMDB_LIBS:+1} -export CRYPTO=@CRYPTO@ diff --git a/bin/tests/system/pytest_custom_markers.py b/bin/tests/system/pytest_custom_markers.py index 55b02f6c58a..9714c0fbf5a 100644 --- a/bin/tests/system/pytest_custom_markers.py +++ b/bin/tests/system/pytest_custom_markers.py @@ -12,6 +12,7 @@ # information regarding copyright ownership. import os +import subprocess import pytest @@ -19,3 +20,23 @@ import pytest long_test = pytest.mark.skipif( not os.environ.get("CI_ENABLE_ALL_TESTS"), reason="CI_ENABLE_ALL_TESTS not set" ) + + +def feature_test(feature): + feature_test_bin = os.environ["FEATURETEST"] + try: + subprocess.run([feature_test_bin, feature], check=True) + except subprocess.CalledProcessError as exc: + if exc.returncode != 1: + raise + return False + return True + + +have_libxml2 = pytest.mark.skipif( + feature_test("--have-libxml2"), reason="libxml2 support disabled in the build" +) + +have_json_c = pytest.mark.skipif( + feature_test("--have-json-c"), reason="json-c support disabled in the build" +) diff --git a/bin/tests/system/statschannel/tests-json.py b/bin/tests/system/statschannel/tests-json.py index d94a32f7da2..312c6830a6b 100755 --- a/bin/tests/system/statschannel/tests-json.py +++ b/bin/tests/system/statschannel/tests-json.py @@ -13,15 +13,12 @@ from datetime import datetime -import os - import pytest import generic +import pytest_custom_markers -pytestmark = pytest.mark.skipif( - not os.environ.get("HAVEJSONSTATS"), reason="json-c support disabled in the build" -) +pytestmark = pytest_custom_markers.have_json_c requests = pytest.importorskip("requests") diff --git a/bin/tests/system/statschannel/tests-xml.py b/bin/tests/system/statschannel/tests-xml.py index 423754916ab..5b187b0f49f 100755 --- a/bin/tests/system/statschannel/tests-xml.py +++ b/bin/tests/system/statschannel/tests-xml.py @@ -11,18 +11,15 @@ # See the COPYRIGHT file distributed with this work for additional # information regarding copyright ownership. -import xml.etree.ElementTree as ET from datetime import datetime - -import os +import xml.etree.ElementTree as ET import pytest import generic +import pytest_custom_markers -pytestmark = pytest.mark.skipif( - not os.environ.get("HAVEXMLSTATS"), reason="libxml2 support disabled in the build" -) +pytestmark = pytest_custom_markers.have_libxml2 requests = pytest.importorskip("requests")