pytest
将停止执行的第一次失败 对于给定的功能测试. 这意味着,如果你有10个案件,但是通过他们向一个单一的测试功能(在一循环,如果),它将停止在第一次失败(即,跳到下一个测试职能,或者退出,如果没有更多的试验的功能)。
为了解决这个问题,标准的方式是确保每10个案件被认为是独立的测试案例。 在这里 的参数化装置 来进入画面。
考虑这个例子:
def my_dataset():
return range(5) # return your datasets from here
@pytest.fixture(params=my_dataset())
def my_fixture(request):
yield request.param # this will `yield` each of the datasets individually, thereby, considering it as individual tests
def test_me(my_fixture):
assert my_fixture < 4
$ pytest tests/test_me.py -vvv
tests/test_me.py::test_me[0] PASSED [ 20%]
tests/test_me.py::test_me[1] PASSED [ 40%]
tests/test_me.py::test_me[2] PASSED [ 60%]
tests/test_me.py::test_me[3] PASSED [ 80%]
tests/test_me.py::test_me[4] FAILED [100%]
================================ FAILURES ================================
_______________________________ test_me[4] _______________________________
my_fixture = 4
def test_me(my_fixture):
> assert my_fixture < 4
E assert 4 < 4
tests/test_me.py:14: AssertionError
======================== short test summary info =========================
FAILED tests/test_me.py::test_me[4] - assert 4 < 4
====================== 1 failed, 4 passed in 0.19s =======================