使用 pytest 随机运行“一些”测试

问题描述 投票:0回答:1

我正在开发一个数值计算应用程序,并且有两组“单元”测试。运行的“快速”测试 < 10ms per tests and "long" tests which take several minutes per test. Let's assume that this is necessary here, for example, when testing an example for the integration of a differential equation. You probably would not see something like this in tests for regular applications or webdev or other things. In numerics, you sometimes have to create relatively large grids (arrays) on which you perform calculations and this takes time.

我正在使用 gitlab 进行自动化(但这应该在某种程度上是通用的)。问题是我无法每次推送一些代码时都运行所有长时间的测试,因为这将需要数十个小时。因此,我们的想法是始终运行所有“快速”测试并运行一些长测试。

有没有办法使用 pytest 来做到这一点?例如,让 pytest 运行测试 2 小时,然后将所有剩余的长测试标记为“预期失败”。或者,让 pytest 运行固定数量的测试。

必须以完全随机的顺序选择运行的测试,以便理想情况下,如果此过程重复多次,所有测试将(几乎肯定)至少执行一次。

python testing pytest
1个回答
0
投票

您目前缺少的重要部分是运行单个测试的历史、典型运行时间的死基。

有了这些,就可以很简单地自动生成测试、套件调用、以随机顺序选择合适的测试。施加 100 秒经过时间或其他时间的预算,然后随机进行一次“长”测试。

© www.soinside.com 2019 - 2024. All rights reserved.