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
704ad2907ff84e84de2f0cfab33ff6ea3d2ea8e4)
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
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
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,
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
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,