首页 > 解决方案 > pytest - 在单独的进程中运行每个测试

问题描述

我正在使用 pytest 运行大量的 python 测试,一些测试结果取决于测试的运行顺序。例如,如果测试 B 在测试 A 之后运行,那么它可能会由于测试 A 中完成的一些影响测试 B 的初始化而失败。为了规避这个问题,我想在新进程中运行每个测试,但测试仍应按顺序运行并且不是并行的。有没有办法用pytest做到这一点?

标签: pythonpytest

解决方案


使用@pytest.mark.order

@pytest.mark.order2
def test_foo():
    assert True

@pytest.mark.order1
def test_bar():
    assert True

推荐阅读