We're sunsetting PodQuest on 2025-07-28. Thank you for your support!
Export Podcast Subscriptions
cover of episode Python 3.14 won't repeat with pytest-repeat

Python 3.14 won't repeat with pytest-repeat

2025/4/1
logo of podcast Test & Code

Test & Code

AI Deep Dive AI Chapters Transcript
People
播音员
主持著名true crime播客《Crime Junkie》的播音员和创始人。
Topics
播音员:pytest-repeat是一个方便的pytest插件,可以重复运行测试用例。它支持通过命令行参数`--count`或测试函数装饰器`@pytest.mark.repeat`来指定重复次数。此外,还可以使用`repeat scope`参数控制重复的范围,例如重复整个测试会话。我在Python 3.13版本上成功测试了该插件,但在Python 3.14版本上却失效了,无法重复运行测试。我尝试修改tox配置文件,在Python 3.14环境下重新测试,问题依然存在。目前我无法解释这种现象,因为从插件的源码来看,它使用了标准的pytest机制,没有明显的错误。这个失效问题没有任何合理解释,我将继续调查原因。

Deep Dive

Shownotes Transcript

Translations:
中文

- PyTest Repeat is a pretty cool plugin to allow you to repeat tests, but currently has an issue with Python 3.14. Welcome to Test & 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 wanna hear more, listen to the outro at the end of the show. Whether you need to get started with PyTest today or wanna power up your PyTest skills, I've got a course for you.

PyTestRepeat is a fun little plugin that allows you to repeat tests. There are a couple ways you can repeat tests. You can pass in a command line parameter called count. So dash dash count equals 10, for instance, will repeat your tests 10 times. Or you can, and that will just repeat all the tests you give it on the command line.

Or you can take an individual test and put a repeat marker. So you'd say, like, PyTest mark repeat and give it the number of times you want a test to repeat if it's just one test.

Now, if you want to do a whole file, for instance, by default, it will repeat each test at a time. So let's say if you repeat three, it'll test the first test three times and then go on to the next test. And if that's not exactly what you want, if you want to go through the entire session and then start over, you can give it a session scope. So there's a repeat scope that you can pass it. So you've got count and repeat scope. Let's say I just wanted to run my entire test suite over and over again until it failed.

You could give it a count of 1000 with a repeat scope of session and also the dash X flag for stop on fail. And it'll just keep running and try to do it 1000 times, but stop as soon as the failure occurs. Super useful, kind of fun for debugging. However, I wanted to try. It looks like it's been tested against 312. I wanted to try it against both Python 3.13 and Python 3.14.

today just to make sure that things are working fine. There's no reason why it shouldn't work because it's just, if I look at the code, PyTestRepeat, the source code, just uses, using fairly standard

PyTest stuff. It uses PyTest generate tests to generate the repeat numbers. Pretty cool way to do that. Anyway, so I went ahead and tried it on Python 3.13. No problems. And then Python 3.14 and it didn't work. And I can't actually figure out why. I thought maybe there was something with my setup. So I modified the toxin, just cloned the repo, modified the toxin and added 3.14 there.

and tried that, tried it with tox, and still this is failing, and I can't figure out why. So for some reason, with Python 3.14, you can't repeat tests. I'll keep looking into it. There is no rational reason why this should not work, but I can't get Python 3.14 to repeat. That's all for now. Now go out and test something. But just test it once. You can't repeat it.

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.