1# Copyright (C) Internet Systems Consortium, Inc. ("ISC") 2# 3# SPDX-License-Identifier: MPL-2.0 4# 5# This Source Code Form is subject to the terms of the Mozilla Public 6# License, v. 2.0. If a copy of the MPL was not distributed with this 7# file, you can obtain one at https://mozilla.org/MPL/2.0/. 8# 9# See the COPYRIGHT file distributed with this work for additional 10# information regarding copyright ownership. 11 12import os 13import pytest 14 15 16def pytest_configure(config): 17 config.addinivalue_line( 18 "markers", "dnspython: mark tests that need dnspython to function" 19 ) 20 21 22def pytest_collection_modifyitems(config, items): 23 # pylint: disable=unused-argument,unused-import,too-many-branches 24 # pylint: disable=import-outside-toplevel 25 26 # Test for dnspython module 27 skip_dnspython = pytest.mark.skip( 28 reason="need dnspython module to run") 29 try: 30 import dns.query # noqa: F401 31 except ModuleNotFoundError: 32 for item in items: 33 if "dnspython" in item.keywords: 34 item.add_marker(skip_dnspython) 35 36 37@pytest.fixture 38def named_port(request): 39 # pylint: disable=unused-argument 40 port = os.getenv("PORT") 41 if port is None: 42 port = 5301 43 else: 44 port = int(port) 45 46 return port 47 48 49@pytest.fixture 50def control_port(request): 51 # pylint: disable=unused-argument 52 port = os.getenv("CONTROLPORT") 53 if port is None: 54 port = 5301 55 else: 56 port = int(port) 57 58 return port 59