为什么pytest不会捕获异常?

时间:2019-08-03 11:11:20

标签: python exception flask pytest

我有一个pytest测试用例,如下所示:

@pytest.fixture
def app():
    app = SampleApp().setup()
    yield app


@pytest.fixture
def client(app):
    return app.test_client()

def test_get_nonexistent_user(client, app):
    with pytest.raises(NotFound) as err:
        user = client.get('/users/5d4001f799556f10b7462e20')

    assert err.type is NotFound

我从pytest documentation所读到的内容应该可以捕获到此异常。相反,我收到的信息如下:

1 failed in 0.25 seconds

我在NotFound错误中看到了traceback错误,所以我确定代码正在引发我期望的异常。

0 个答案:

没有答案