Getting started with pytest Transcripts
Chapter: Markers
Lecture: Skipping tests with pytest.mark.skip
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
We'll go through examples of all the markers that I use frequently X fail,
0:07
skip, skip if and custom markers and let's start with a simple test of sorting So the card object that we're using within the cards application,
0:18
it seems like it would make sense if we would be able to have the user be able to sort the cards if we wanted to.
0:25
So what I mean by that is if I have a list of cards here, I've got just filling in the summary with Z's and A's and if I call
0:33
sorted on that I should get back a sorted list and therefore so I put a with Z to begin with an A to be afterwards and then we should end
0:44
up with A. And then Z. That seems to make sense. I don't know if this works yet but let's give it a shot. We're in chapter five and we do pytest test,
0:57
sort the less than operator is not supported between instances of card and card. Okay, so that's a bummer. Set that aside for now. What do we wanna do?
1:09
We could just say that this isn't supported in this feature in this version yet, maybe in the next version. So maybe let's skip this test but I think I
1:18
want to zoom in. So it's said that the less than isn't supported. So let's zoom in and do a test that just tests less than so def if
1:33
I just give it a couple of cards and block that in card one card two a task can be tasked. Now I should be able to compare them.
1:41
C1 should be less than C2. So I should get the same error is as before we'll do a short trace back this time. Yeah so we get the same error.
1:53
So both of these I could focus zoom in and focus on both of them and that would make this sort of work.
2:00
But for now it doesn't. So for now we can compare this with equality but
2:06
we cannot compare these with less than just for sanity sake let's make sure that we know that we can do equality.
2:14
one test passed and it's our that last one just for reference it is the equality works but the others don't. So let's skip these for now.
2:25
So for now until we get a chance to implement this feature. I'm gonna just skip them. So we skip them by doing pytest mark,
2:33
skip except for we have to import pytest first. Oops let's do this in a different file so that we don't mess this up as
2:45
a as a general thing. So like copy this. Let's do it within our skip file. Okay I'll clean this up, I'll clean this up later or now.
2:58
So that's what we started with and then our skip is here we've already got it started. We want to skip these two for now let's just see if that works
3:07
for skipping different file. We did skip now skipped with unconditional skip. Don't really like to leave it at that. So let's put a reason for these.
3:21
So I always like to do a reason for skips and my reason is sorting or sort not supported. Maybe less than not supported.
3:31
And then we can do the same thing for the other test there. Now, if we run this we get less than not supported.
3:43
Yeah, we could do sort not supported because sort doesn't support it because of less than But cool, sort not supported.
3:51
Less than not supported. Sort then. Okay, I'll get this right eventually. Great. Now we have skip figured out. Next we look at skip if.