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

Cannot dynamically mark a test as xfail #3100

Closed
gbgbgbg opened this issue Jan 9, 2018 · 10 comments
Closed

Cannot dynamically mark a test as xfail #3100

gbgbgbg opened this issue Jan 9, 2018 · 10 comments
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@gbgbgbg
Copy link

gbgbgbg commented Jan 9, 2018

From inside a test, the test cannot be marked as xfail (or xpass)

This is useful when particular test combinations are invalid.

I believe the test xtest_dynamic_xfail_set_during_setup covers this case, but by starting with xtest, it is not being run. I have not found any documented reason for its exclusion, nor a ticket that addresses.

@pytestbot
Copy link
Contributor

GitMate.io thinks the contributor most likely able to help you is @RonnyPfannschmidt.

@RonnyPfannschmidt
Copy link
Member

test_dynamic_xfail_no_run shows how it currently works in a kind of messy way, i beleive that mechanism can be used to do what i think you asked for

please report if my guess was correct

@RonnyPfannschmidt RonnyPfannschmidt added the type: question general question, might be closed after 2 weeks of inactivity label Jan 9, 2018
@gbgbgbg
Copy link
Author

gbgbgbg commented Jan 9, 2018

I want to be able to mark a test as xfail, and then let it run, and have a possibility of generating a XPASS result

@gbgbgbg
Copy link
Author

gbgbgbg commented Jan 9, 2018

ah, it looks like run=True is the trick!

This will work for me, but the xtest_dynamic_xfail_set_during_setup case is more natural for me

Why is xtest_dynamic_xfail_set_during_setup disabled?

@RonnyPfannschmidt
Copy link
Member

according to the history 8 years ago when applymarker got introduced the test had gotten "disabled"

@RonnyPfannschmidt
Copy link
Member

i'm closing as the actual question seems to be answered, in case something is missing please call out and thanks

@gbgbgbg
Copy link
Author

gbgbgbg commented Jan 9, 2018

is there a ticket for re-enabling xtest_dynamic_xfail_set_during_setup ?

@RonnyPfannschmidt
Copy link
Member

no, alos that test uses a mechanism which instead of modifying the collected test, it modifies the function of the test (which may be used in different tests

as part of the upcoming mark cleanup we are going to remove that mechanism eventually (with some deprecation grace periods

@sharan-cs2000
Copy link

this is due to
assert 0, "Could this be represented as an exemption" --> comparing against integer value, upon failure you will above issues, correcting this to:
assert "Could this be represented as an exemption", "Could this be represented as an exemption" --> correct values

XFAIL This is stdout

XFAIL This is stderr

As work-around we can use it accordingly, need to look assert() against sys.stdout.write/sys.stderr.write usage..

@rth
Copy link

rth commented Aug 17, 2018

test_dynamic_xfail_no_run shows how it currently works in a kind of messy way, i beleive that mechanism can be used to do what i think you asked for

For other users who end up here, the following appears to work,

def test_something(request):
    if some_dynamic_condition:
        request.applymarker(pytest.mark.xfail(run=False))

    # continue running the code below in any case
    some_other_code()

It might be helpful to have this as part of the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

5 participants