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

Test is not marked as xfailed #134

Closed
MaxoH4uk opened this issue Aug 4, 2023 · 1 comment
Closed

Test is not marked as xfailed #134

MaxoH4uk opened this issue Aug 4, 2023 · 1 comment

Comments

@MaxoH4uk
Copy link

MaxoH4uk commented Aug 4, 2023

Hello!

When i call the method pytest.xfail() the test is marked as XFAIL:

def test_foo():
    pytest.xfail()

image

But if before calling the method pytest.xfail() any of the methods pytest_check returns false, then the test is marked as failed:

def test_foo():
    pytest_check.is_true(1 == 2, 'qwerty')
    pytest.xfail()

image

@okken
Copy link
Owner

okken commented Aug 11, 2023

Yep. That will happen if using the standard pytest.xfail() function.
The reason is that the implementation of pytest.xfail() is to raise an exception. See implementation.
The xfail() function doesn't just mark the test as xfail, it raises an exception and stops the test.

The workarounds are.

  1. Use the @pytest.mark.xfail decorator on the function if you know the test function is always xfail.
  2. If you need some collection time logic to determine xfail-ness, use the condition parameter to @pytest.mark.xfail().
  3. If you need to determine xfail-ness at test runtime, then try using the pytest-runtime-xfail plugin and the runtime_xfail fixture. You still may need to call the function before the check.is_true() is called, but honestly I don't remember.

I hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants