psf / requests

A simple, yet elegant, HTTP library.

Home Page:https://requests.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pytest.warns(None) is no longer supported

wRAR opened this issue · comments

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

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).

And this is the code we are talking about:

with pytest.warns(None) as warning_records:
warnings.simplefilter("always")
requests.get(f"https://localhost:{port}/", verify=ca_bundle)

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

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