在pytest固定装置中导入应用时出错

阿尔特姆·克里沃尼斯(Artem Kryvonis)

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__.pyapp

但是这个夹具会引发错误

ImportError: Error importing plugin "client_fixtures": No module named 'app'

包装结构

Core
    app-
        ...
        __init__.py

    tests-
        client_fixture.py

也许会有所帮助

当我使用PyCharm运行测试时,一切正常,我只需在测试文件夹上单击鼠标右键,然后执行“在测试中运行py.test”

rjsberry

您需要pytest像这样致电

python -m pytest tests/

文档中

这几乎等同于pytest tests/直接调用命令行脚本,除了Python还将当前目录添加到sys.path中。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章