gpt4 book ai didi

python - pytest - 在单独的进程中运行每个测试

转载 作者:行者123 更新时间:2023-12-01 09:16:43 25 4
gpt4 key购买 nike

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

最佳答案

使用@pytest.mark.order

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

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

关于python - pytest - 在单独的进程中运行每个测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51187188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com