我有一个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
错误,所以我确定代码正在引发我期望的异常。