Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 786 Bytes

File metadata and controls

44 lines (29 loc) · 786 Bytes

PT016

no message passed to pytest.fail()

The function pytest.fail must be called either with a positional argument, a keyword argument reason= (since pytest version 7.0.0), or a keyword argument msg= (for compatibility with older versions of pytest). Passing a keyword argument under a wrong name will also be reported as a violation.

Examples

Bad code:

import pytest

def test_foo():
    pytest.fail()

def test_bar():
    pytest.fail('')

def test_baz():
    pytest.fail(message='...')  # wrong kwarg name

Good code:

import pytest

def test_foo():
    pytest.fail('...')

def test_bar():
    pytest.fail(reason='...')

def test_baz():
    pytest.fail(msg='...')

Rationale

  • to make it easier to understand and debug test failures