Python 3.x 使用PyTest夹具测试烧瓶时出现属性错误
有人能解释一下我如何在测试中使用pytest夹具吗 我得到了这个Python 3.x 使用PyTest夹具测试烧瓶时出现属性错误,python-3.x,flask,pytest,Python 3.x,Flask,Pytest,有人能解释一下我如何在测试中使用pytest夹具吗 我得到了这个conftest.py,其中定义了3个pytest夹具: {...} @pytest.fixture(scope='session', autouse=True) def app(request): app = create_app({ 'TESTING': True }) ctx = app.app_context() ctx.push() def teardown():
conftest.py
,其中定义了3个pytest夹具:
{...}
@pytest.fixture(scope='session', autouse=True)
def app(request):
app = create_app({
'TESTING': True
})
ctx = app.app_context()
ctx.push()
def teardown():
ctx.pop()
request.addfinalizer(teardown)
return app
@pytest.fixture(scope='function')
def client(app, request):
return app.test_client()
@pytest.fixture(scope='function')
def get(client):
return humanize_werkzeug_client(client.get)
我正在尝试使用上述测试装置测试我的应用程序。基于我的理解,我需要在测试中使用app
fixture。如图所示,我试过这样的方法:
def test_myflaskapp(app):
response = app.get('/')
assert response.status_code == 200
但是我得到一个属性错误:AttributeError:'Flask'对象没有属性'get'
。这对我来说毫无意义,我恐怕不确定它是否适用于我的案件
有人能解释一下我做错了什么吗?我正在尝试学习
Flask
/PyTest
,但我找不到一个示例/指南来解释它是如何工作的。应用程序夹具返回一个Flask
实例,我想您应该使用。在上获取方法。尝试在测试中将app
更改为client
退房