测试的执行得到停止后一种说法的错误在pytest

0

的问题

对于数据驱动的测试,如果有10个数据集,并断言失败3的数据集,然后将其余的7个数据集是不是认为对于执行和程序被停止在这一点上完全。 我们试图通过removeing的"提高电子"的路线和时间的所有数据集被认为对于执行,但在年底,该状况是显示为通过这是绝对不正确的,因为我需要报告的失败3的数据集。 请让我知道如果你有任何解决方案的相同。

我已经试过以下方法2,并且它没有工作。 对于第一个测试的情况下执行10次于10的数据集,但即使在发生故障后的第3数据集、测试的执行状况是显示为通过这是不正确的,因为测试情况下应该是失败的报告。

对第二个试验的执行得到完全停止后的断言未在第3数据集以及剩下的数据集被认为不执行。

我的目标是执行试验的情况下所有的数据集在一次,然后检查的报告的任何失败的。

        try:
            assert len(json_response_plan) == 1
        except Exception:
            pytest.raises(Exception)


        try:
            assert len(json_response_plan) == 1
        except Exception as e:
            raise e
automated-tests pytest python
2021-11-24 05:12:42
1

最好的答案

1

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 =======================
2021-11-29 08:35:15

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................