Skip to content

xfail doesn't actually run the test (but the docs promise that it does) #810

Closed
@inducer

Description

@inducer

From http://pytest.org/latest/skipping.html#mark-a-test-function-as-expected-to-fail:

This test will be run but no traceback will be reported when it fails. Instead terminal reporting will list it in the “expected to fail” or “unexpectedly passing” sections.

Consider this snippet:

def test_xfail():
    import pytest
    pytest.xfail("doesn't work")

    import os
    os._exit(0)

This produces an "x" in the pytest output. If the test were actually run beyond the xfail as documented, then the interpreter should have just exited. What xfail seems to do is terminate the execution of the test. But that's inconvenient. Suppose you have a test that'll always raise an exception. You'd have to wrap the test in a try block and call xfail in a finally clause. Instead, pytest should mark the test as expecting to fail and continue on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs informationreporter needs to provide more information; can be closed after 2 or more weeks of inactivitytype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions