Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 817 Bytes

PT011.md

File metadata and controls

43 lines (30 loc) · 817 Bytes

PT011

set the match parameter in pytest.raises({exception})

Configuration

  • pytest-raises-require-match-for
    Comma-separated list of exception names that require a match= parameter in a pytest.raises() call. By default the list contains the following exceptions:
    • BaseException, Exception
    • ValueError
    • OSError, IOError, EnvironmentError, socket.error

Examples

Bad code:

import pytest

def test_foo():
    with pytest.raises(ValueError):
        ...

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

Good code:

import pytest

def test_foo():
    with pytest.raises(ValueError, match='expected message'):
        ...

Rationale

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