1#!/usr/bin/python3 2 3# Copyright (C) Internet Systems Consortium, Inc. ("ISC") 4# 5# SPDX-License-Identifier: MPL-2.0 6# 7# This Source Code Form is subject to the terms of the Mozilla Public 8# License, v. 2.0. If a copy of the MPL was not distributed with this 9# file, you can obtain one at https://mozilla.org/MPL/2.0/. 10# 11# See the COPYRIGHT file distributed with this work for additional 12# information regarding copyright ownership. 13 14import os 15import subprocess 16 17import pytest 18 19 20long_test = pytest.mark.skipif( 21 not os.environ.get("CI_ENABLE_ALL_TESTS"), reason="CI_ENABLE_ALL_TESTS not set" 22) 23 24 25def feature_test(feature): 26 feature_test_bin = os.environ["FEATURETEST"] 27 try: 28 subprocess.run([feature_test_bin, feature], check=True) 29 except subprocess.CalledProcessError as exc: 30 if exc.returncode != 1: 31 raise 32 return False 33 return True 34 35 36have_libxml2 = pytest.mark.skipif( 37 not feature_test("--have-libxml2"), reason="libxml2 support disabled in the build" 38) 39 40have_json_c = pytest.mark.skipif( 41 not feature_test("--have-json-c"), reason="json-c support disabled in the build" 42) 43 44 45try: 46 import flaky as flaky_pkg 47except ModuleNotFoundError: 48 # In case the flaky package is not installed, run the tests as usual 49 # without any attempts to re-run them. 50 # pylint: disable=unused-argument 51 def flaky(*args, **kwargs): 52 """Mock decorator that doesn't do anything special, just returns the function.""" 53 54 def wrapper(wrapped_obj): 55 return wrapped_obj 56 57 return wrapper 58 59else: 60 flaky = flaky_pkg.flaky 61