diff --git a/tests/external_httplib/test_urllib.py b/tests/external_httplib/test_urllib.py index 8d9dd1820..9b2fde350 100644 --- a/tests/external_httplib/test_urllib.py +++ b/tests/external_httplib/test_urllib.py @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os +import sys import pytest try: import urllib.request as urllib -except: +except ImportError: import urllib from testing_support.external_fixtures import cache_outgoing_headers, insert_incoming_headers @@ -29,6 +29,14 @@ from newrelic.api.background_task import background_task +# Since Python 3.3, `urllib.URLopener()` has been deprecated in favor of +# `urllib.request.urlopen`. In Python 3.14, `urllib.URLopener()` will be +# removed. `urllib.request.urlopen` corresponds to the old `urllib2.urlopen` + +SKIP_IF_PYTHON_3_14_OR_ABOVE = pytest.mark.skipif( + sys.version_info[0:2] >= (3, 14), reason="urllib.URLopener() is removed in Python 3.14 and above" +) + @pytest.fixture(scope="session") def metrics(server): @@ -44,6 +52,7 @@ def metrics(server): return scoped, rollup +@SKIP_IF_PYTHON_3_14_OR_ABOVE def test_urlopener_http_request(server, metrics): @validate_transaction_metrics( "test_urllib:test_urlopener_http_request", @@ -59,6 +68,7 @@ def _test(): _test() +@SKIP_IF_PYTHON_3_14_OR_ABOVE def test_urlopener_https_request(server, metrics): @validate_transaction_metrics( "test_urllib:test_urlopener_https_request", @@ -77,6 +87,7 @@ def _test(): _test() +@SKIP_IF_PYTHON_3_14_OR_ABOVE def test_urlopener_http_request_with_port(server): scoped = [(f"External/localhost:{server.port}/urllib/", 1)] @@ -110,6 +121,7 @@ def _test(): ] +@SKIP_IF_PYTHON_3_14_OR_ABOVE @validate_transaction_metrics( "test_urllib:test_urlopener_file_request", scoped_metrics=_test_urlopener_file_request_scoped_metrics, @@ -123,6 +135,7 @@ def test_urlopener_file_request(): opener.open(file_uri) +@SKIP_IF_PYTHON_3_14_OR_ABOVE @background_task() @cache_outgoing_headers @validate_cross_process_headers @@ -131,6 +144,7 @@ def test_urlopener_cross_process_request(server): opener.open(f"http://localhost:{server.port}/") +@SKIP_IF_PYTHON_3_14_OR_ABOVE @cat_enabled def test_urlopener_cross_process_response(server): _test_urlopener_cross_process_response_scoped_metrics = [ diff --git a/tests/external_httplib/test_urllib2.py b/tests/external_httplib/test_urllib2.py index 54aeed721..c744614be 100644 --- a/tests/external_httplib/test_urllib2.py +++ b/tests/external_httplib/test_urllib2.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import urllib.request as urllib2 import pytest