flake8-pytest-style icon indicating copy to clipboard operation
flake8-pytest-style copied to clipboard

Rule to disallow conditional test definition

Open m-burst opened this issue 5 years ago • 0 comments

Rule request

Description

Test definition should not be placed in a top-level if block. pytest.mark.skipif() should be used instead, if necessary.

Bad code:

if sys.platform == 'win32':
    def test_on_windows_only():
        ...

Good code:

@pytest.mark.skipif(sys.platform != 'win32', reason='windows only')
def test_on_windows_only():
    ...

Rationale

  • for consistency
  • to make such conditionally skipped tests appear in the report

m-burst avatar May 07 '20 19:05 m-burst