Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference documentation, typing annotations and reality for pytest.mark.xfail() don’t match #10094

Open
manueljacob opened this issue Jul 1, 2022 · 3 comments
Labels
topic: typing type-annotation issue type: docs documentation improvement, missing or needing clarification type: enhancement new feature or API change, should be merged into features branch

Comments

@manueljacob
Copy link
Contributor

manueljacob commented Jul 1, 2022

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 no reason behaves like passing None to 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 for reason is in fact "unconditional skip" (code).
  • raises: The type (according to the type annotations) is Union[Type[BaseException], Tuple[Type[BaseException], ...]] instead of Type[Exception]. Neither captures the fact that None can be passed to it (which is also the documented default value).
  • strict=False: The default value of strict is actually determined by the xfail_strict config (code).
@manueljacob manueljacob changed the title Documentation for pytest.mark.xfail() is wrong Reference documentation for pytest.mark.xfail() is wrong Jul 1, 2022
@manueljacob manueljacob changed the title Reference documentation for pytest.mark.xfail() is wrong Reference documentation, typing annotations and reality for pytest.mark.xfail() don’t match Jul 1, 2022
@Zac-HD Zac-HD added type: enhancement new feature or API change, should be merged into features branch type: docs documentation improvement, missing or needing clarification topic: typing type-annotation issue labels Jul 4, 2022
bluetech added a commit to bluetech/pytest that referenced this issue Aug 12, 2023
bluetech added a commit to bluetech/pytest that referenced this issue Aug 12, 2023
@TanyaAgarwal28
Copy link
Contributor

Hi @Zac-HD I would like to pick this up

@Zac-HD
Copy link
Member

Zac-HD commented Oct 12, 2023

@TanyaAgarwal28 you don't need permission to open a PR, just go ahead.

Like most maintainers, I'm a volunteer and prefer not to be pinged on issues or PRs - I'm already subscribed to everything I want notifications about. Someone will review your PRs when they have free time; and if they don't it could be a while. That's just how volunteer projects go!

TanyaAgarwal28 added a commit to TanyaAgarwal28/pytest that referenced this issue Oct 13, 2023
TanyaAgarwal28 added a commit to TanyaAgarwal28/pytest that referenced this issue Oct 13, 2023
@Avasam
Copy link
Contributor

Avasam commented Oct 22, 2023

Allowing condition=None (as show in the current doc method signature) can also reduce overly verbose redundant code. See this example from setuptools:

    @pytest.mark.xfail(
        # Argument of type "str | None" cannot be assigned to parameter "condition" of type "str | bool" in function "__call__" Pylance[reportGeneralTypeIssues]
        # Argument 1 to "__call__" of "_XfailMarkDecorator" has incompatible type "Optional[str]"; expected "Union[str, bool]" Mypy[arg-type]
        os.environ.get('PYTHONDONTWRITEBYTECODE'),
        reason="Byte code disabled",
    )
    def test_exclude_source_files(self, setup_context, user_override): ...

Where the current workaround is os.environ.get('PYTHONDONTWRITEBYTECODE', False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: typing type-annotation issue type: docs documentation improvement, missing or needing clarification type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

4 participants