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
我在app
包的__init__.py
内有固定装置和函数create_app()
但是这个装置会引发错误
ImportError:导入插件“client_fixtures”时出错:没有名为“app”的模块
包结构
Core
app-
...
__init__.py
tests-
client_fixture.py
Maybe it will be helpful
当我使用 PyCharm 运行测试时,一切正常 我只需在测试文件夹上单击鼠标右键并执行“在测试中运行 py.test”
最佳答案
您需要调用pytest
,如下所示:
python -m pytest tests/
来自documentation :
This is almost equivalent to invoking the command line script
pytest tests/
directly, except that Python will also add the current directory to sys.path.
关于python - 在 pytest 装置中导入应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46315803/