Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wRAR opened this issue Apr 7, 2024 · 4 comments · Fixed by #6682
Closed

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

wRAR opened this issue Apr 7, 2024 · 4 comments · Fixed by #6682

Comments

@wRAR
Copy link

wRAR commented Apr 7, 2024

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
Copy link
Contributor

frenzymadness commented Apr 11, 2024

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
Copy link
Contributor

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)

@frenzymadness
Copy link
Contributor

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

@psf psf deleted a comment from kloczek Apr 11, 2024
frenzymadness added a commit to frenzymadness/requests that referenced this issue Apr 11, 2024
`pytest.warns(None)` has been deprecated in pytest 7.0.0
and it's no longer working in pytest 8.

Resolves: psf#6679
frenzymadness added a commit to frenzymadness/requests that referenced this issue Apr 11, 2024
`pytest.warns(None)` has been deprecated in pytest 7.0.0
and it's no longer working in pytest 8.

Resolves: psf#6679
@frenzymadness
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants