Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在pytest中,将测试标记为从夹具内部通过_Python_Unit Testing_Testing_Pytest_Python Unittest - Fatal编程技术网

Python 在pytest中,将测试标记为从夹具内部通过

Python 在pytest中,将测试标记为从夹具内部通过,python,unit-testing,testing,pytest,python-unittest,Python,Unit Testing,Testing,Pytest,Python Unittest,使用或,我可以从夹具内部将测试标记为跳过或失败。没有pytest.pass。我怎样才能把它标记为通过 导入pytest @pytest.fixture def fixture(): #pytest.skip() pytest.xfail() def测试(夹具): 断言错误 不幸的是,我不知道通过夹具测试的方法,但您可以在测试中使用pytest.skip和msg,例如“pass”,conftest.py的钩子将检查此“pass”消息并使测试通过: conftest.py import pytest

使用或,我可以从夹具内部将测试标记为跳过或失败。没有
pytest.pass
。我怎样才能把它标记为通过

导入pytest
@pytest.fixture
def fixture():
#pytest.skip()
pytest.xfail()
def测试(夹具):
断言错误

不幸的是,我不知道通过夹具测试的方法,但您可以在测试中使用pytest.skip和msg,例如“pass”,conftest.py的钩子将检查此“pass”消息并使测试通过:

conftest.py

import pytest


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(call):
    outcome = yield
    if outcome.get_result().outcome == 'skipped' and call.excinfo.value.msg == 'pass':
        outcome.get_result().outcome = 'passed'
# -*- coding: utf-8 -*-
import pytest


def test_skip_pass():
    pytest.skip('pass')


def test_skip_pass_2():
    pytest.skip('skip')
测试跳过.py

import pytest


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(call):
    outcome = yield
    if outcome.get_result().outcome == 'skipped' and call.excinfo.value.msg == 'pass':
        outcome.get_result().outcome = 'passed'
# -*- coding: utf-8 -*-
import pytest


def test_skip_pass():
    pytest.skip('pass')


def test_skip_pass_2():
    pytest.skip('skip')
结果:

收集。。。收集2项

test_skip.py::test_skip_pass通过[50%]
test_skip.py::test_skip_pass_2跳过[100%]
跳过:跳过

=====================================1个通过,1个在0.04秒内跳过=========================


结束测试是一个passreturnsomevalue,我想它意味着“通过”测试。不确定为什么要这样做:)针对
pytest
LOLA测试提出问题只有当它已执行且未提出时,测试才能通过。如果测试未执行,则跳过该测试。如果在测试失败或未运行时,您不得不撒谎并表示测试通过,那么测试设计是严重错误的。虽然您可以修改“未通过”的测试结果,但它隐藏是有原因的。@finefoot我不是故意显得傲慢,对此表示抱歉。我也不是选民。尽管如此,我还是建议不要改变测试结果来模拟统计数据。你能给出一个更好地描述你的问题的例子吗?