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

Rule that suggests explicit `strict=` in `@pytest.mark.xfail`

Open lengau opened this issue 1 year ago • 2 comments

Rule request

Description

Detect use of the @pytest.mark.xfail decorator and ensure it explicitly sets a strict=True or strict=False rather than allowing silent (and possibly accidental) use of the default False configuration.

Rationale

The pytest.mark.xfail decorator has a strict parameter that defaults to False, making xfail in CI roughly equivalent to a skip rather than failing if the test passes. This would prevent accidentally committing xfail tests that get hidden in CI.

lengau avatar Oct 24 '23 18:10 lengau

Hi @lengau,

Thanks for the issue! Unfortunately I'm not sure about it. I agree that strict xfail should always be preferred to non-strict, but it is probably better to set it globally in the config file, instead of bugging developers with lint errors on each individual test.

There already is issue #24 which suggests to verify that the config file follows the best practices (including xfail_strict = True)

m-burst avatar Nov 02 '23 13:11 m-burst

the plan in pytest is to make xfail strict by default again

RonnyPfannschmidt avatar Nov 17 '23 21:11 RonnyPfannschmidt