问题描述
我的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 (将#修改为@)