Hi everyone, I have the following scenario
I want to set testing as XFail with condition depending on results of an API call to JIRA, however I would like to perform my authentication against JIRA only once before all the tests, so I do it in a fixture of scope session defined in conftest.py, but the problem is that if in a test I have a marker of @pytest.mark.xfail, I can't access the value that the fixture of scope session returns
Any idea of how to deal with this cases ?
Thanks and let me know if you need more detail about the scenario
you can xfail at runtime with pytest.xfail:
def test(fix):
if do_something(fix):
pytest.xfail('expected failure for Y reason')
Hi,
Yes but if I understand correctly in that case the test will stop running and the result will be XFail
I want the regular XFail behavior where:
1) Test runs completely
2) If test fails then the result is XFail
3) If test passes then the result is XPass
Is it possible to achieve this ?
I was thinking of maybe in the setup of the test (Where I have already available the fixture) add dynamically the marker of XFail, but I am not sure how to do it
ah yes, I see what you mean, try this?
@pytest.fixture
def fix():
return True
def test(fix, request):
if fix:
request.node.add_marker(pytest.mark.xfail)
...
Seems that might be worth checking, will try and update you
Thanks !!!!
Closing this as inactive - hopefully it worked!
Most helpful comment
ah yes, I see what you mean, try this?