pytest只运行更改的文件?

2024-09-19 20:41:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python相当陌生,正在尝试学习工具集。在

我已经知道如何让py.test -f在编写代码时监视我的测试。有一件事我还没弄明白,是否有一种方法可以让观察者变得更聪明,就像Ruby的Guard库一样。在

使用guard+minitest,我得到的行为是,如果我保存一个像my_class.rb的文件,然后执行my_class_test.rb,如果我在cli中点击enter,它将运行所有测试。在

到目前为止,使用pytest,我还不能找到一种方法来只运行与最后一次接触的文件相对应的测试文件,从而避免了等待整个测试套件运行,直到当前文件通过为止。在

你们这些Python会怎么做?在

谢谢!在


Tags: 文件方法代码pytestmyclass观察者
3条回答

还有一个pytest-xdist具有一个称为:

looponfail: run your tests repeatedly in a subprocess. After each run py.test waits until a file in your project changes and then re-runs the previously failing tests. This is repeated until all tests pass after which again a full run is performed.

一种可能是将pytest-testmonpytest-watch一起使用。在

它使用coverage.py来跟踪哪个测试触及了哪一行代码,一旦您更改了一行代码,它就会重新运行以某种方式执行该行的所有测试。在

要添加到上述编译器的答案中,您可以使用pytest watch的 runner选项让pytest-testmon和{a2}一起玩:

ptw  runner "pytest  testmon"

相关问题 更多 >