mirror of
https://github.com/isc-projects/bind9.git
synced 2026-02-27 03:51:16 -05:00
Fix skipping tests requiring the requests module
The intended purpose of the @pytest.mark.requests decorator was to cause
Python-based parts of the "statschannel" system test to be skipped if
the requests Python module is not available. However, both
tests-json.py and tests-xml.py contain a global "import requests"
statement which triggers ImportError exceptions during test
initialization if the requests module is not available. In other words,
the @pytest.mark.requests decorator serves no useful purpose.
Since all tests in both tests-json.py and tests-xml.py depend on the
requests Python module, employ pytest.importorskip() to ensure the
Python-based parts of the "statschannel" system test are skipped when
the requests module is not available. Remove all occurrences of the
@pytest.mark.requests decorator (and all associated code) to prevent
confusion.
(cherry picked from commit 704ad2907f)
This commit is contained in:
parent
4fac33c9d5
commit
dbddc22187
3 changed files with 2 additions and 30 deletions
|
|
@ -13,26 +13,6 @@ import os
|
|||
import pytest
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
config.addinivalue_line(
|
||||
"markers", "requests: mark tests that need requests to function"
|
||||
)
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
# pylint: disable=unused-argument,unused-import,too-many-branches
|
||||
# pylint: disable=import-outside-toplevel
|
||||
# Test for requests module
|
||||
skip_requests = pytest.mark.skip(
|
||||
reason="need requests module to run")
|
||||
try:
|
||||
import requests # noqa: F401
|
||||
except ModuleNotFoundError:
|
||||
for item in items:
|
||||
if "requests" in item.keywords:
|
||||
item.add_marker(skip_requests)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def statsport(request):
|
||||
# pylint: disable=unused-argument
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ from datetime import datetime
|
|||
import os
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
import generic
|
||||
|
||||
pytestmark = pytest.mark.skipif(not os.environ.get('HAVEJSONSTATS'),
|
||||
reason='json-c support disabled in the build')
|
||||
requests = pytest.importorskip('requests')
|
||||
|
||||
|
||||
# JSON helper functions
|
||||
|
|
@ -75,27 +75,23 @@ def load_zone_json(zone):
|
|||
return name
|
||||
|
||||
|
||||
@pytest.mark.requests
|
||||
def test_zone_timers_primary_json(statsport):
|
||||
generic.test_zone_timers_primary(fetch_zones_json, load_timers_json,
|
||||
statsip="10.53.0.1", statsport=statsport,
|
||||
zonedir="ns1")
|
||||
|
||||
|
||||
@pytest.mark.requests
|
||||
def test_zone_timers_secondary_json(statsport):
|
||||
generic.test_zone_timers_secondary(fetch_zones_json, load_timers_json,
|
||||
statsip="10.53.0.3", statsport=statsport,
|
||||
zonedir="ns3")
|
||||
|
||||
|
||||
@pytest.mark.requests
|
||||
def test_zone_with_many_keys_json(statsport):
|
||||
generic.test_zone_with_many_keys(fetch_zones_json, load_zone_json,
|
||||
statsip="10.53.0.2", statsport=statsport)
|
||||
|
||||
|
||||
@pytest.mark.requests
|
||||
def test_traffic_json(named_port, statsport):
|
||||
generic_dnspython = pytest.importorskip('generic_dnspython')
|
||||
generic_dnspython.test_traffic(fetch_traffic_json,
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ from datetime import datetime
|
|||
import os
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
import generic
|
||||
|
||||
pytestmark = pytest.mark.skipif(not os.environ.get('HAVEXMLSTATS'),
|
||||
reason='libxml2 support disabled in the build')
|
||||
requests = pytest.importorskip('requests')
|
||||
|
||||
|
||||
# XML helper functions
|
||||
|
|
@ -105,27 +105,23 @@ def load_zone_xml(zone):
|
|||
return name
|
||||
|
||||
|
||||
@pytest.mark.requests
|
||||
def test_zone_timers_primary_xml(statsport):
|
||||
generic.test_zone_timers_primary(fetch_zones_xml, load_timers_xml,
|
||||
statsip="10.53.0.1", statsport=statsport,
|
||||
zonedir="ns1")
|
||||
|
||||
|
||||
@pytest.mark.requests
|
||||
def test_zone_timers_secondary_xml(statsport):
|
||||
generic.test_zone_timers_secondary(fetch_zones_xml, load_timers_xml,
|
||||
statsip="10.53.0.3", statsport=statsport,
|
||||
zonedir="ns3")
|
||||
|
||||
|
||||
@pytest.mark.requests
|
||||
def test_zone_with_many_keys_xml(statsport):
|
||||
generic.test_zone_with_many_keys(fetch_zones_xml, load_zone_xml,
|
||||
statsip="10.53.0.2", statsport=statsport)
|
||||
|
||||
|
||||
@pytest.mark.requests
|
||||
def test_traffic_xml(named_port, statsport):
|
||||
generic_dnspython = pytest.importorskip('generic_dnspython')
|
||||
generic_dnspython.test_traffic(fetch_traffic_xml,
|
||||
|
|
|
|||
Loading…
Reference in a new issue