Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 797 Bytes

File metadata and controls

43 lines (30 loc) · 797 Bytes

PT030

pytest.warns({warning}) is too broad, set the match parameter or use a more specific warning

Configuration

  • pytest-warns-require-match-for
    Comma-separated list of warning names that require a match= parameter in a pytest.warning() call. By default the list contains the following warnings:
    • Warning
    • UserWarning
    • DeprecationWarning

Examples

Bad code:

import pytest

def test_foo():
    with pytest.warns(UserWarning):
        ...

    # empty string is also an error
    with pytest.warns(UserWarning, match=''):
        ...

Good code:

import pytest

def test_foo():
    with pytest.warns(UserWarning, match='expected message'):
        ...

Rationale

  • to help ensure that the pytest.warns clause is not too broad