client_fixture.py
import pytest
from app.apis import api
from app import create_app
@pytest.fixture
def app_client(credentials, redis_cred_setup):
app = create_app(credentials['app_config_name'])
api.init_app(app)
client = app.test_client()
return client
我有夹具和功能create_app()
里面__init__.py
的app
包
但是这个夹具会引发错误
ImportError: Error importing plugin "client_fixtures": No module named 'app'
包装结构
Core
app-
...
__init__.py
tests-
client_fixture.py
也许会有所帮助
当我使用PyCharm运行测试时,一切正常,我只需在测试文件夹上单击鼠标右键,然后执行“在测试中运行py.test”
您需要pytest
像这样致电:
python -m pytest tests/
从文档中:
这几乎等同于
pytest tests/
直接调用命令行脚本,除了Python还将当前目录添加到sys.path中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句