pytest-repeat - works fine on Python 3.14
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.
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 py test 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 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 pytest-repeat 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 pytest-repeat 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 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. These doing module in class has never really made sense to me for repeat. So I usually either do 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. And you can decorate that test with pytestMarkRepeat, 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 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 Tox 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.
Creators and Guests
