pytest

时间:2018-11-14 10:15:26

标签: python pytest

我是pytest的新手,正在尝试使用pytest.xfail装饰器。

我的问题是我得到的输出是否太多/错误,因此表明我做错了。我问的原因是我在其他示例中看到的更多。最终摘要确实正确显示为1 xfailed in 2.61 seconds

我正在测试一个Flask应用,该应用应在Hello World上将get返回到/

@pytest.fixture
def client():
    client = application.app.test_client()
    yield client


@pytest.mark.xfail(reason='should fail')
def test_hello_world(client):
    r = client.get('/')
    assert r.get_json() == '12Hello World'

输出为

test_application.py x
client = <FlaskClient <Flask 'application'>>

    @pytest.mark.xfail(reason='should fail')
    def test_hello_world(client):
    r = client.get('/')
>       assert r.get_json() == '12Hello World'
E       AssertionError: assert 'Hello World' == '12Hello World'
E         - Hello World
E         + 12Hello World
E         ? ++

test_application.py:30: AssertionError
                                                [100%]

========================== 1 xfailed in 2.61 seconds ==========================

它真的可以显示错误和所有内容吗?我看到的其他示例仅显示x,表明预期的测试失败。另外,它没有显示reason,这也让我感到惊讶。运行时,我没有-v(详细)参数。我在Pycharm中运行测试。

0 个答案:

没有答案
相关问题