Today I'd like to talk about PyTest Repeat again. We're going to cover a few things. First off, PyTest Repeat works fine on Python 3.14. Second, I'm going to briefly explain PyTest Repeat again. And third, I need to explain the last episode, the April 1st episode.
Welcome to Test and Code. Before we get started, I wanted to mention that I've made some changes to the course offerings for PyTest training at courses.pythontest.com. If you want to hear more, listen to the outro at the end of the show. Whether you need to get started with PyTest today or want to power up your PyTest skills, I've got a course for you.
So, PyTest Repeat. Why am I covering PyTest Repeat again? Well, partly so that I can repeat myself, because that's kind of a joke. But also, there was a misunderstanding with some people of the last episode.
I'll just tell you that PyTest repeat is now being tested on Python 3.9 through 3.14. Why those versions? Well, just to prove to you that it works fine on Python 3.14, but also because those are the supported versions or upcoming versions for Python. Python 3.8 and before are end of life, and it is fairly standard practice for PyTest.
Python package maintainers to only test for Python versions that are not end-of-life. So right now that's 3.9 and above. We're going to talk about what PyTestRepeat is again. I talked about it last week, but I still haven't decided whether or not I'm going to delete that episode. I'm going to leave it up for now. The reason why I might delete it was it was an April Fool's episode gone wrong, and we'll talk about that at the end. So first, I'll repeat what PyTestRepeat does
And that's okay because it's a great plugin. PyTest Repeat allows you to repeat tests. There's a couple of ways you can drive it. You can pass dash dash count with a number. So like say 10. And then by default, you'll run the first test 10 times and then the second test 10 times. Really all of the collected tests will run 10 times and they'll repeat before going on to the next test.
If you'd rather have it run through the whole suite and then repeat and do that whole suite 10 times, there's a repeat scope flag that you can set to session. There are other options, but I usually either leave it by default or set it to session. The other options are, well, all of the options are session, module, class, and function. It's function by default, which means it repeats every function every
and then goes on to the next function. But if you set it to session, it goes through the sessions. If you set it to module, it'll test each test module, like test file, 10 times, and then go on to the next file. Doing module in class has never really made sense to me for repeat, so I usually either just do function or session. Anyway.
If you just want to focus on a particular set of tests, like you have a particular couple, two or three, or maybe even one test that you really want to have it run a few times, you can use a decorator instead of passing it in. You can decorate that test with pytest mark repeat, and then you give it a number there also. And then it runs the rest of the suite just like normal. And when it gets to that test, it runs it like 10 times or whatever number you've put in. That's awesome.
A cool trick when trying to find an intermittent test failure is to pick a biggish number for your suite. So if your suite runs for, say, five minutes, then picking a count of 12 would take about an hour. But if your suite runs in like a minute, then you need a count of like 60 to run an hour. See what I mean? Pick a number.
that's long enough to hit the, pick a number that's long enough that you think you'll hit the intermittent failure. So then you could just run the suite with dash dash count and then repeat scope equals session and then give it dash X. This will run your test session and then stop at the first failure. Turn this on.
and like go to lunch or something. And if the failure happens by the time you get back, then the system under test will be in the failure state ready to debug. Neat. Now on to the April Fool's joke. On April 1st, I released an episode claiming that PyTest repeat didn't work on Python 3.14, that there was no rational reason for this. Therefore, Python 3.14 won't repeat. That was the joke. Some of you got that that was a joke.
It was actually my first attempt on this podcast to do an April Fool's prank. Some people didn't get it though, and I don't blame you. It really wasn't that funny, but I thought it was funny. Anyway, and you know the saying that if you have to explain your joke, it's not funny? Well, we're there. So, Python 3.14 is the next major Python release.
It's due later this year, but you can already test it by using the alpha releases. 3.14 is also the beginning digits of pi. Pi does not repeat. Like, the digits of pi don't repeat. Pi is an irrational number. Irrational in the sense that pi cannot be expressed as a ratio of two integers. I was playing on all of this. No rational reason.
because pi is irrational. Python doesn't repeat? Kind of sounds like pi doesn't repeat. Also, I was already doing this series of pytest plugins, so I threw pytest repeat into the mix, just for a dumb math and Python joke. Anyway, that's it. That's the joke. If anybody has a better April Fool's joke or prank idea to do next year, let me know.
By the way, I use PyTest Repeat frequently and help maintain it. We just released a new version with very few changes. There's not changes to the code. There's just changes to the structure around it. We are now testing Python 3.13 and 3.14, both in talks and in CI. That's all for now. Now go ahead and test something. Now go out and test something. Now go out and test something. See? Repeat works fine. I'll stop now.
Thanks to everyone who supported the show via Patreon or by learning PyTest from a course at courses.pythontest.com. I've made a change recently that I'm pretty excited about. The Complete PyTest Course is now the Complete PyTest Course Bundle. It was one big course and is now three courses.
since you really need them at different times in your PyTest journey. Part 1, PyTest Primary Power, provides a gentle introduction up through covering the superpowers of PyTest, including fixtures, parameterization, markers, and more. Grab primary power and get to work. Part 2, using PyTest with projects, has strategic topics like debugging, mocking, continuous integration. Part 2 is perfect for when you're applying PyTest to a work or open source project. Part
Part 3: PyTest Booster Rockets, Explore's plugins, both third-party and building your own,
and advanced parameterization. Although part three can be taken right after the other two, it makes more sense to live with pytest for a while and then explore what more you can do with it. I've also added new intro videos at the beginning of each course, congratulations videos at the end, and printable certificates. Anyway, I think the new structure makes a lot more sense. These are all at courses.pythontest.com. That's all for today. Thanks for listening. Now go ahead and test something.