如何解决进行pytest时,为烧瓶应用程序使用单独的virtualenv
我的conftest.py
中有以下装置
@pytest.fixture(scope="session")
def client(app):
app.config['TESTING'] = False
return app.test_client()
@pytest.fixture(scope="session")
def calculate(client):
def _calculate(pathtojson,return_format='json_only'):
r = client.post('/calculate',headers={'Content-type': 'application/json'},data=open(pathtojson,'rb')
)
return r
return _calculate
test_flaskapp.py
然后看起来像这样:
def test_flaskapp(calculate):
pathtojson = './some/path/to/a/json'
r = calculate(pathtojson)
json_response = r.get_json()
assert json_response['SOMEKEY'] == SOMEVALUE
assert r.status_code == 200
为执行我的flask应用程序,我在virtualenv中使用了pypy(需要在执行复杂计算的flask应用程序中提高速度)。对于测试,我想使用单独的virtualenv 作为pypy,a)干扰了我用于性能分析的某些测试程序包,b)减慢了测试速度(我不知道为什么)。
之前,我有一个单独的子进程,将烧瓶在其virtualenv中旋转起来,在我的测试中,我只调用了生成的本地主机(我没有使用上面的装置),但这在使用pytest-cov进行覆盖率测量时会遇到问题
所以我的问题是:有什么方法可以用pytest和做测试吗?
- 在一个virtualenv中运行pytest
- 在带有pypy的单独virtualenv中运行要测试的flask应用程序
- 确保pytest-cov能够衡量覆盖率 ?
任何帮助或指针,将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。