pytest
pytest copied to clipboard
Reference documentation, typing annotations and reality for `pytest.mark.xfail()` don’t match
The documentation for pytest.mark.xfail() does not match reality.
-
reason=None: If no conditions are passed,reason’s default is""(code). Adding@pytest.mark.xfail(reason=None, strict=True)to a passing test results in “TypeError: can only concatenate str (not "NoneType") to str”. If a condition is passed, passing noreasonbehaves like passingNoneto it (code). I’m unsure how this subtlety could be captured in the function signature.pytest.mark.skipif()has the same issue.pytest.mark.skip()’s default value forreasonis in fact "unconditional skip" (code). -
raises: The type (according to the type annotations) isUnion[Type[BaseException], Tuple[Type[BaseException], ...]]instead ofType[Exception]. Neither captures the fact thatNonecan be passed to it (which is also the documented default value). -
strict=False: The default value ofstrictis actually determined by thexfail_strictconfig (code).