Getting started with pytest Transcripts
Chapter: Markers
Lecture: Expecting tests to fail with pytest.mark.xfail
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
For X fail, it works a lot, like skip If it you can pass in, if I just say, instead of skip, if I just say X fail,
0:12
what's this is gonna do is it's going to it, you can give it a condition and you can give it the same reason less than
0:20
not supported by one X. And then instead of a skip, we're gonna get get an X fail if this fails, but I guess the difference is this actually runs it,
0:31
this will run the test instead of skipping it, so let's try this. Just the only thing we did was change skip to X fail. So pytest -V,
0:45
test xfail and yeah, that's it, we got an X fail here. it's kind of neat to see what happens if this passes,
0:57
so I'm gonna show you what this looks like if it passes instead of fails, but let's just leave this one in this test in place and do a like
1:07
an xpass demo, let's pass. And the reason is X pass demo and X file doesn't require a condition. You can use a condition but it's not required.
1:22
So this is an xpass demo. And what happens? Oh, we wanted to actually pass,
1:27
so instead of comparison less than we can just do equality and actually have them equal. So that should pass, let's try a running X fail now,
1:48
so the we have X fail. and X pass and they show up, they don't show up as passes or fails, they show up as X passes or X fails.
1:58
And so that's a different sort of a thing. And when we don't do verbose, if we just do normal one instead of dots,
2:08
we get this X for the X fail and and X for X pass Now, we can also say that I so actually I do think this
2:19
isn't really gonna fail, I'm not expecting it to fail, but I can say, I really think that I'm certain that it's going to fail
2:27
You can say strict, not it might fail, but I know it's gonna fail and that way if it passes, if it does fail, it will just be like a normal X fail.
2:40
But if it passes and you said, I think it's gonna fail, it will show up. Let's watch, it shows up as a failure, that's kind of what we want.
2:49
So strict strict turns X passes into fails. So that's really what strict is on your X fail marker X fail in all its
2:59
flavors. You got, you got X pass X fail. Well, this is an Xpass demo, but this is how you use X pass or fail without a condition.
3:09
You can use X fail with a condition, so skip, has skip and skipif.
3:13
X fail, it's just built into it, you can give it condition or you dont have to give a condition.