psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
52.16k stars 9.33k forks source link

2.31.0: pytest fails in `tests/test_requests.py::TestRequests::test_https_warnings` unit #6639

Closed kloczek closed 9 months ago

kloczek commented 9 months ago

I'm packaging your module as an rpm package so I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

Here is pytest output: ```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-requests-2.31.0-4.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-requests-2.31.0-4.fc35.x86_64/usr/lib/python3.8/site-packages + /usr/bin/pytest -ra -m 'not network' tests ============================= test session starts ============================== platform linux -- Python 3.8.18, pytest-8.0.0, pluggy-1.3.0 rootdir: /home/tkloczko/rpmbuild/BUILD/requests-2.31.0 configfile: pyproject.toml plugins: httpbin-2.0.0, mock-3.12.0 collected 596 items tests/test_help.py ... [ 0%] tests/test_hooks.py ... [ 1%] tests/test_lowlevel.py .................... [ 4%] tests/test_packages.py ... [ 4%] tests/test_requests.py ................................................. [ 13%] ......................................................................Fpytest-httpbin server hit an exception serving request: [SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:1131) attempting to ignore so the rest of the tests can run . [ 25%] ........................................................................ [ 37%] .....................................x.................................. [ 49%] ........................................................ [ 58%] tests/test_structures.py .................... [ 62%] tests/test_testserver.py ......s.... [ 63%] tests/test_utils.py ..s................................................. [ 72%] ........................................................................ [ 84%] ........................................................................ [ 96%] ...sssssssssss..... [100%] =================================== FAILURES =================================== _______________________ TestRequests.test_https_warnings _______________________ self = nosan_server = ('localhost', 36135, '/tmp/pytest-of-tkloczko/pytest-145/certs0/ca.pem') @pytest.mark.skipif( SNIMissingWarning is None, reason="urllib3 2.0 removed that warning and errors out instead", ) def test_https_warnings(self, nosan_server): """warnings are emitted with requests.get""" host, port, ca_bundle = nosan_server if HAS_MODERN_SSL or HAS_PYOPENSSL: warnings_expected = ("SubjectAltNameWarning",) else: warnings_expected = ( "SNIMissingWarning", "InsecurePlatformWarning", "SubjectAltNameWarning", ) > with pytest.warns(None) as warning_records: tests/test_requests.py:1014: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = WarningsChecker(record=True), expected_warning = None, match_expr = None def __init__( self, expected_warning: Optional[ Union[Type[Warning], Tuple[Type[Warning], ...]] ] = Warning, match_expr: Optional[Union[str, Pattern[str]]] = None, *, _ispytest: bool = False, ) -> None: check_ispytest(_ispytest) super().__init__(_ispytest=True) msg = "exceptions must be derived from Warning, not %s" if expected_warning is None: > warnings.warn(WARNS_NONE_ARG, stacklevel=4) E pytest.PytestRemovedIn8Warning: Passing None has been deprecated. E See https://docs.pytest.org/en/latest/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests for alternatives in common use cases. /usr/lib/python3.8/site-packages/_pytest/recwarn.py:279: PytestRemovedIn8Warning ================================== XFAILURES =================================== _______________ TestRequests.test_response_iter_lines_reentrant ________________ self = httpbin = .inner at 0x7f08b08c8ee0> @pytest.mark.xfail def test_response_iter_lines_reentrant(self, httpbin): """Response.iter_lines() is not reentrant safe""" r = requests.get(httpbin("stream/4"), stream=True) assert r.status_code == 200 next(r.iter_lines()) > assert len(list(r.iter_lines())) == 3 E assert 2 == 3 E + where 2 = len([b'"http://127.0.0.1:43743/stream/4", "args": {}, "headers": {"Host": "127.0.0.1:43743", "User-Agent": "python-request..."Accept-Encoding": "gzip, deflate, br", "Accept": "*/*", "Connection": "keep-alive"}, "origin": "127.0.0.1", "id": 3}']) E + where [b'"http://127.0.0.1:43743/stream/4", "args": {}, "headers": {"Host": "127.0.0.1:43743", "User-Agent": "python-request..."Accept-Encoding": "gzip, deflate, br", "Accept": "*/*", "Connection": "keep-alive"}, "origin": "127.0.0.1", "id": 3}'] = list() E + where = >() E + where > = .iter_lines tests/test_requests.py:2106: AssertionError ----------------------------- Captured stderr call ----------------------------- 127.0.0.1 - - [14/Feb/2024 21:46:02] "GET /stream/4 HTTP/1.1" 200 1008 =============================== warnings summary =============================== tests/test_requests.py::TestRequests::test_set_basicauth[42-42] tests/test_requests.py::TestRequests::test_set_basicauth[42-42] /home/tkloczko/rpmbuild/BUILD/requests-2.31.0/requests/auth.py:36: DeprecationWarning: Non-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in (42) to a string or bytes object in the near future to avoid problems. warnings.warn( tests/test_requests.py::TestRequests::test_set_basicauth[42-42] tests/test_requests.py::TestRequests::test_set_basicauth[42-42] /home/tkloczko/rpmbuild/BUILD/requests-2.31.0/requests/auth.py:46: DeprecationWarning: Non-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in () to a string or bytes object in the near future to avoid problems. warnings.warn( tests/test_requests.py::TestRequests::test_set_basicauth[None-None] tests/test_requests.py::TestRequests::test_set_basicauth[None-None] /home/tkloczko/rpmbuild/BUILD/requests-2.31.0/requests/auth.py:36: DeprecationWarning: Non-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in (None) to a string or bytes object in the near future to avoid problems. warnings.warn( tests/test_requests.py::TestRequests::test_set_basicauth[None-None] tests/test_requests.py::TestRequests::test_set_basicauth[None-None] /home/tkloczko/rpmbuild/BUILD/requests-2.31.0/requests/auth.py:46: DeprecationWarning: Non-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in () to a string or bytes object in the near future to avoid problems. warnings.warn( tests/test_utils.py::TestContentEncodingDetection::test_none tests/test_utils.py::TestContentEncodingDetection::test_pragmas[] tests/test_utils.py::TestContentEncodingDetection::test_pragmas[] tests/test_utils.py::TestContentEncodingDetection::test_pragmas[] tests/test_utils.py::TestContentEncodingDetection::test_pragmas[] tests/test_utils.py::TestContentEncodingDetection::test_precedence /home/tkloczko/rpmbuild/BUILD/requests-2.31.0/requests/utils.py:493: DeprecationWarning: In requests 3.0, get_encodings_from_content will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.) warnings.warn( -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =========================== short test summary info ============================ SKIPPED [1] tests/test_testserver.py:94: this fails non-deterministically under pytest-xdist SKIPPED [1] tests/test_utils.py:49: condition: cStringIO is None SKIPPED [10] tests/test_utils.py:814: Test only on Windows SKIPPED [1] tests/test_utils.py:867: Test only on Windows XFAIL tests/test_requests.py::TestRequests::test_response_iter_lines_reentrant FAILED tests/test_requests.py::TestRequests::test_https_warnings - pytest.Pyt... = 1 failed, 581 passed, 13 skipped, 1 xfailed, 14 warnings in 78.45s (0:01:18) = 127.0.0.1 - - [14/Feb/2024 21:45:55] "GET /get HTTP/1.1" 200 210 127.0.0.1 - - [14/Feb/2024 21:45:55] "GET /relative-redirect/20 HTTP/1.1" 302 0 127.0.0.1 - - [14/Feb/2024 21:45:56] "GET /get HTTP/1.1" 200 272 127.0.0.1 - - [14/Feb/2024 21:45:56] "GET /cookies HTTP/1.1" 200 40 127.0.0.1 - - [14/Feb/2024 21:45:56] "HEAD /get HTTP/1.1" 200 0 127.0.0.1 - - [14/Feb/2024 21:46:00] "GET /get HTTP/1.1" 200 313 127.0.0.1 - - [14/Feb/2024 21:46:00] "POST /post HTTP/1.1" 200 475 127.0.0.1 - - [14/Feb/2024 21:46:01] "GET /get?f%C3%B8%C3%B8=f%C3%B8%C3%B8 HTTP/1.1" 200 340 127.0.0.1 - - [14/Feb/2024 21:46:01] "GET /get?f%C3%B8%C3%B8=f%C3%B8%C3%B8 HTTP/1.1" 200 340 127.0.0.1 - - [14/Feb/2024 21:46:01] "GET /get?foo=foo HTTP/1.1" 200 300 127.0.0.1 - - [14/Feb/2024 21:46:01] "PUT /put HTTP/1.1" 200 447 127.0.0.1 - - [14/Feb/2024 21:46:02] "GET /get HTTP/1.1" 200 272 127.0.0.1 - - [14/Feb/2024 21:46:32] "GET /redirect-to?url=http%3A%2F%2Flocalhost%3A-1 HTTP/1.1" 302 0 ```
List of installed modules in build env: ```console Package Version ----------------------------- -------- alabaster 0.7.16 attrs 23.2.0 Babel 2.14.0 blinker 1.6.2 Brotli 1.1.0 build 1.0.3 cffi 1.16.0 chardet 5.2.0 charset-normalizer 3.3.2 click 8.1.7 cppclean 0.13 cryptography 42.0.2 decorator 5.1.1 distro 1.9.0 dnf 4.19.0 docutils 0.20.1 exceptiongroup 1.1.3 flasgger 0.9.7.1 Flask 3.0.2 gpg 1.23.2 greenlet 3.0.3 httpbin 0.10.1 idna 3.6 imagesize 1.4.1 importlib_metadata 7.0.1 importlib_resources 6.1.1 iniconfig 2.0.0 installer 0.7.0 itsdangerous 2.1.2 Jinja2 3.1.3 jsonschema 4.19.1 jsonschema-specifications 2023.7.1 libdnf 0.73.0 MarkupSafe 2.1.3 mistune 2.0.5 packaging 23.2 pkgutil_resolve_name 1.3.10 pluggy 1.3.0 ply 3.11 pycparser 2.21 Pygments 2.17.2 pyproject_hooks 1.0.0 PySocks 1.7.1 pytest 8.0.0 pytest-httpbin 2.0.0 pytest-mock 3.12.0 python-dateutil 2.8.2 pytz 2024.1 PyYAML 6.0.1 referencing 0.30.2 requests 2.31.0 rpds-py 0.18.0 setuptools 69.1.0 six 1.16.0 snowballstemmer 2.2.0 Sphinx 7.1.2 sphinxcontrib-applehelp 1.0.4 sphinxcontrib-devhelp 1.0.5 sphinxcontrib-htmlhelp 2.0.5 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.7 sphinxcontrib-serializinghtml 1.1.10 tomli 2.0.1 trustme 1.1.0 urllib3 1.26.18 Werkzeug 3.0.1 wheel 0.42.0 zipp 3.17.0 ```

Please let me know if you need more details or want me to perform some diagnostics.

kloczek commented 9 months ago

I've tested as well 2.31.0 + current master (a5a0e4b5) and it fails as well

```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-requests-2.31.0-4.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-requests-2.31.0-4.fc35.x86_64/usr/lib/python3.8/site-packages + /usr/bin/pytest -ra -m 'not network' tests ============================= test session starts ============================== platform linux -- Python 3.8.18, pytest-8.0.0, pluggy-1.3.0 rootdir: /home/tkloczko/rpmbuild/BUILD/requests-2.31.0 configfile: pyproject.toml plugins: httpbin-2.0.0, mock-3.12.0 collected 597 items tests/test_help.py ... [ 0%] tests/test_hooks.py ... [ 1%] tests/test_lowlevel.py .................... [ 4%] tests/test_packages.py ... [ 4%] tests/test_requests.py ................................................. [ 13%] ......................................................................Fpytest-httpbin server hit an exception serving request: [SSL: TLSV1_ALERT_UNKNOWN_CA] tlsv1 alert unknown ca (_ssl.c:1131) attempting to ignore so the rest of the tests can run . [ 25%] ........................................................................ [ 37%] .....................................x.................................. [ 49%] ......................................................... [ 58%] tests/test_structures.py .................... [ 62%] tests/test_testserver.py ......s.... [ 63%] tests/test_utils.py ..s................................................. [ 72%] ...........................F............................................ [ 84%] ........................................................................ [ 96%] ...sssssssssss..... [100%] =================================== FAILURES =================================== _______________________ TestRequests.test_https_warnings _______________________ self = nosan_server = ('localhost', 37739, '/tmp/pytest-of-tkloczko/pytest-152/certs0/ca.pem') @pytest.mark.skipif( SNIMissingWarning is None, reason="urllib3 2.0 removed that warning and errors out instead", ) def test_https_warnings(self, nosan_server): """warnings are emitted with requests.get""" host, port, ca_bundle = nosan_server if HAS_MODERN_SSL or HAS_PYOPENSSL: warnings_expected = ("SubjectAltNameWarning",) else: warnings_expected = ( "SNIMissingWarning", "InsecurePlatformWarning", "SubjectAltNameWarning", ) > with pytest.warns(None) as warning_records: tests/test_requests.py:1004: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = WarningsChecker(record=True), expected_warning = None, match_expr = None def __init__( self, expected_warning: Optional[ Union[Type[Warning], Tuple[Type[Warning], ...]] ] = Warning, match_expr: Optional[Union[str, Pattern[str]]] = None, *, _ispytest: bool = False, ) -> None: check_ispytest(_ispytest) super().__init__(_ispytest=True) msg = "exceptions must be derived from Warning, not %s" if expected_warning is None: > warnings.warn(WARNS_NONE_ARG, stacklevel=4) E pytest.PytestRemovedIn8Warning: Passing None has been deprecated. E See https://docs.pytest.org/en/latest/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests for alternatives in common use cases. /usr/lib/python3.8/site-packages/_pytest/recwarn.py:279: PytestRemovedIn8Warning ______________ TestExtractZippedPaths.test_zipped_paths_extracted ______________ self = tmpdir = local('/tmp/pytest-of-tkloczko/pytest-152/test_zipped_paths_extracted0') def test_zipped_paths_extracted(self, tmpdir): zipped_py = tmpdir.join("test.zip") with zipfile.ZipFile(zipped_py.strpath, "w") as f: f.write(__file__) _, name = os.path.splitdrive(__file__) zipped_path = os.path.join(zipped_py.strpath, name.lstrip(r"\/")) extracted_path = extract_zipped_paths(zipped_path) assert extracted_path != zipped_path assert os.path.exists(extracted_path) > assert filecmp.cmp(extracted_path, __file__) E AssertionError: assert False E + where False = ('/tmp/test_utils.py', '/home/tkloczko/rpmbuild/BUILD/requests-2.31.0/tests/test_utils.py') E + where = filecmp.cmp tests/test_utils.py:337: AssertionError ================================== XFAILURES =================================== _______________ TestRequests.test_response_iter_lines_reentrant ________________ self = httpbin = .inner at 0x7fe9478564c0> @pytest.mark.xfail def test_response_iter_lines_reentrant(self, httpbin): """Response.iter_lines() is not reentrant safe""" r = requests.get(httpbin("stream/4"), stream=True) assert r.status_code == 200 next(r.iter_lines()) > assert len(list(r.iter_lines())) == 3 E assert 2 == 3 E + where 2 = len([b'"http://127.0.0.1:36813/stream/4", "args": {}, "headers": {"Host": "127.0.0.1:36813", "User-Agent": "python-request..."Accept-Encoding": "gzip, deflate, br", "Accept": "*/*", "Connection": "keep-alive"}, "origin": "127.0.0.1", "id": 3}']) E + where [b'"http://127.0.0.1:36813/stream/4", "args": {}, "headers": {"Host": "127.0.0.1:36813", "User-Agent": "python-request..."Accept-Encoding": "gzip, deflate, br", "Accept": "*/*", "Connection": "keep-alive"}, "origin": "127.0.0.1", "id": 3}'] = list() E + where = >() E + where > = .iter_lines tests/test_requests.py:2093: AssertionError ----------------------------- Captured stderr call ----------------------------- 127.0.0.1 - - [14/Feb/2024 22:52:05] "GET /stream/4 HTTP/1.1" 200 1008 =============================== warnings summary =============================== tests/test_requests.py::TestRequests::test_set_basicauth[42-42] tests/test_requests.py::TestRequests::test_set_basicauth[42-42] /home/tkloczko/rpmbuild/BUILDROOT/python-requests-2.31.0-4.fc35.x86_64/usr/lib/python3.8/site-packages/requests/auth.py:36: DeprecationWarning: Non-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in (42) to a string or bytes object in the near future to avoid problems. warnings.warn( tests/test_requests.py::TestRequests::test_set_basicauth[42-42] tests/test_requests.py::TestRequests::test_set_basicauth[42-42] /home/tkloczko/rpmbuild/BUILDROOT/python-requests-2.31.0-4.fc35.x86_64/usr/lib/python3.8/site-packages/requests/auth.py:46: DeprecationWarning: Non-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in () to a string or bytes object in the near future to avoid problems. warnings.warn( tests/test_requests.py::TestRequests::test_set_basicauth[None-None] tests/test_requests.py::TestRequests::test_set_basicauth[None-None] /home/tkloczko/rpmbuild/BUILDROOT/python-requests-2.31.0-4.fc35.x86_64/usr/lib/python3.8/site-packages/requests/auth.py:36: DeprecationWarning: Non-string usernames will no longer be supported in Requests 3.0.0. Please convert the object you've passed in (None) to a string or bytes object in the near future to avoid problems. warnings.warn( tests/test_requests.py::TestRequests::test_set_basicauth[None-None] tests/test_requests.py::TestRequests::test_set_basicauth[None-None] /home/tkloczko/rpmbuild/BUILDROOT/python-requests-2.31.0-4.fc35.x86_64/usr/lib/python3.8/site-packages/requests/auth.py:46: DeprecationWarning: Non-string passwords will no longer be supported in Requests 3.0.0. Please convert the object you've passed in () to a string or bytes object in the near future to avoid problems. warnings.warn( tests/test_utils.py::TestContentEncodingDetection::test_none tests/test_utils.py::TestContentEncodingDetection::test_pragmas[] tests/test_utils.py::TestContentEncodingDetection::test_pragmas[] tests/test_utils.py::TestContentEncodingDetection::test_pragmas[] tests/test_utils.py::TestContentEncodingDetection::test_pragmas[] tests/test_utils.py::TestContentEncodingDetection::test_precedence /home/tkloczko/rpmbuild/BUILDROOT/python-requests-2.31.0-4.fc35.x86_64/usr/lib/python3.8/site-packages/requests/utils.py:489: DeprecationWarning: In requests 3.0, get_encodings_from_content will be removed. For more information, please see the discussion on issue #2266. (This warning should only appear once.) warnings.warn( -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html =========================== short test summary info ============================ SKIPPED [1] tests/test_testserver.py:94: this fails non-deterministically under pytest-xdist SKIPPED [1] tests/test_utils.py:50: condition: cStringIO is None SKIPPED [10] tests/test_utils.py:815: Test only on Windows SKIPPED [1] tests/test_utils.py:868: Test only on Windows XFAIL tests/test_requests.py::TestRequests::test_response_iter_lines_reentrant FAILED tests/test_requests.py::TestRequests::test_https_warnings - pytest.Pyt... FAILED tests/test_utils.py::TestExtractZippedPaths::test_zipped_paths_extracted = 2 failed, 581 passed, 13 skipped, 1 xfailed, 14 warnings in 78.67s (0:01:18) = 127.0.0.1 - - [14/Feb/2024 22:51:58] "GET /relative-redirect/45 HTTP/1.1" 302 0 127.0.0.1 - - [14/Feb/2024 22:51:58] "GET /cookies HTTP/1.1" 200 40 127.0.0.1 - - [14/Feb/2024 22:51:58] "HEAD /get HTTP/1.1" 200 0 127.0.0.1 - - [14/Feb/2024 22:52:02] "GET /get HTTP/1.1" 200 313 127.0.0.1 - - [14/Feb/2024 22:52:03] "GET /get?f%C3%B8%C3%B8=f%C3%B8%C3%B8 HTTP/1.1" 200 340 127.0.0.1 - - [14/Feb/2024 22:52:03] "GET /get?foo=foo HTTP/1.1" 200 300 127.0.0.1 - - [14/Feb/2024 22:52:04] "GET /get HTTP/1.1" 200 272 127.0.0.1 - - [14/Feb/2024 22:52:05] "GET /get HTTP/1.1" 200 272 ```
nateprewitt commented 9 months ago

The issue is originating from your upgrading outside of our currently defined testing infrastructure requirements. We do not currently support pytest 8.0.0 which is the source of your test failures. Please run the tests with the prescribed requirements, otherwise this will be addressed when support for pytest 8.0 is added.

kloczek commented 9 months ago

If it is issue related to use pytest 8.x IMO better would be keep this ticket opened with only renamed subject as sooner or later move to pytest 8 needs to be done.