question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pytest.xfail should work like pytest.mark.xfail

See original GitHub issue

pytest.xfail should do exactly what pytest.mark.xfail does. pytest.xfail acts like pytest.skip for no good reason. pytest.xfail should let the test run then mark it as XFAIL or XPASS.

The current pytest.xfail already exists as pytest.fail and new delayed pytest.xfail should developed in place.

https://github.com/pytest-dev/pytest/issues/7060 https://github.com/pytest-dev/pytest/issues/810

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
RonnyPfannschmidtcommented, Jan 2, 2021

Thanks for looking it up

I Strongly prefer the declarative way as it implies the Metadata is available after collection

1reaction
rhshadrachcommented, Jan 1, 2021

This can be accomplished via the request fixture. I don’t know why pytest.xfail doesn’t do the same, but I also don’t understand pytest internals. Minimal example:

@pytest.mark.parametrize("arg", [1, 2, 3, 4])
def test_foo(request, arg):
    if arg == 2 or arg == 3:
        request.applymarker(pytest.mark.xfail)
    assert arg in (1, 2)

1 passes, 2 fails (xpass strict), 3 xfails, and 4 fails.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use skip and xfail to deal with tests that cannot succeed
pytest counts and lists skip and xfail tests separately. ... The simplest way to skip a test function is to mark it with...
Read more >
How and why I use pytest's xfail - Paul Ganssle
I would be inclined to instead add a custom pytest.mark.heavy test, and configure your test runner to skip things that are marked as...
Read more >
Pytest - Xfail/Skip Tests - Tutorialspoint
In this chapter, we will learn about the Skip and Xfail tests in Pytest. Now, consider the below situations −. A test is...
Read more >
@pytest.mark.xfail - pytest Quick Start Guide [Book] - O'Reilly
You can use @pytest.mark.xfail decorator to indicate that a test is expected to fail . As usual, we apply the mark decorator to...
Read more >
marking a test as xfail with double parameterize in pytest
You could create a function that will be executed in tests collection time and handles the parametrization and the the xfail mark based...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found