psf / requests

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

pytest.warns(None) is no longer supported #6679

Closed wRAR closed 1 month ago

wRAR commented 1 month ago

Not sure what was this code supposed to mean (making sure that there are no warnings? I don't think it ever did that?), but on pytest 8 it no longer works: "TypeError: exceptions must be derived from Warning, not <class 'NoneType'>"

https://docs.pytest.org/en/latest/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests

frenzymadness commented 1 month ago

From the pytest's changelog:

8645: pytest.warns(None) is now deprecated because many people used it to mean “this code does not emit warnings”, but it actually had the effect of checking that the code emits at least one warning of any type - like pytest.warns() or pytest.warns(Warning).

frenzymadness commented 1 month ago

And this is the code we are talking about:

https://github.com/psf/requests/blob/2a438c27b5a5828c8ea0dc958112eecffca70b12/tests/test_requests.py#L1006-L1008

frenzymadness commented 1 month ago

In our testing environment with pytest 8.1.1 and urllib3 < 2.0 removing the None from pytest.warns fixes the problem.

frenzymadness commented 1 month ago

I'm not sure why the last comment by @kloczek has been removed but PR with the simple fix is ready.