Skip to content

pytest.warns(None) does not fail if warnings are raised. #8644

Closed
@Jasha10

Description

@Jasha10

I expect that pytest.warns(None) is an assertion that no warnings are raised.

import warnings
import pytest

def test_no_warning():
    with pytest.warns(None):
        warnings.warn("Look out!")

Running pytest on the above does not fail. I would expect a failure, something like "a warning was raised where no warning was expected".

$ pip list
Package    Version
---------- -------------------
attrs      21.2.0
certifi    2020.12.5
iniconfig  1.1.1
packaging  20.9
pip        21.0.1
pluggy     0.13.1
py         1.10.0
pyparsing  2.4.7
pytest     6.2.4
setuptools 52.0.0.post20210125
toml       0.10.2
wheel      0.36.2
$ python --version
Python 3.9.4

OS: Ubuntu 18.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: docsdocumentation improvement, missing or needing clarificationtype: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions