簡體   English   中英

Pytest-並行執行測試用例兩次

[英]Pytest-parallel executing test case twice

對於並行執行,我使用 pytest-parallel,它可以工作,但每個測試用例都執行兩次

def test_2():
    assert 2==2

def test_3():
    assert 1 == 1

使用的命令

pytest -v -s test_file.py --workers auto

什么 auto 會觸發與測試一樣多的工作人員(每個測試用例的每個工作人員)

和結果

collected 2 items
pytest-parallel: 8 workers (processes), 1 test per worker (thread)

testing_parallel.py::test_2 PASSED
testing_parallel.py::test_2 PASSED
testing_parallel.py::test_3 PASSED
testing_parallel.py::test_3 PASSED

嘗試過 --workers 2

collected 2 items
pytest-parallel: 2 workers (processes), 1 test per worker (thread)

testing_parallel.py::test_2
testing_parallel.py::test_3 PASSED
testing_parallel.py::test_2 PASSEDPASSED
testing_parallel.py::test_3 PASSED

這里只有測試用例,但每個測試用例執行兩次

實際上,您的測試只執行一次。

問題是日志記錄顯示結果兩次。

如果您嘗試在代碼中打印,您會看到它們只會在控制台中出現一次。

def test_2():
    print("Im running test 2")
    assert 2==2

def test_3():
    print("Im running test 3")
    assert 1 == 1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM