python - pytest-django 找不到 Django 项目
问题描述
尝试用 django 配置 pytest,该项目已经有很多不是用 pytest 编写的测试(用 unittest 编写),但我试图让它们用 pytest 运行,这样我就可以编写 pytest 测试并让它与旧测试一起使用。
我知道 pytest-django 在 django 项目的根目录中检查 manage.py 文件,但是这个项目的 manage.py 文件不在根目录中,所以我想这就是为什么当我运行pytest
但运行 pytest时抛出下面的错误并提供特定文件的作品。如何指定 manage.py 在哪里?因为我在文档中找不到这个
pytest-django could not find a Django project (no manage.py file could be found).
You must explicitly add your Django project to the Python path to have it picked up.
解决方案
您可以定义要运行的 python 命令的 python 路径:
PYTHONPATH=/your/path/to/your/django/project/ pytest
或在运行 pytest 命令之前导出您的 pythonpath:
export PYTHONPATH=/your/path/to/your/django/project/
pytest
推荐阅读
- javascript - 使用 Firebase 数据库规则禁用特定子项的写入
- postgresql - 使用 psycopg2 使用 ACCESS EXCLUSIVE 锁定表
- azure - MS Azure:无法将 Azure 云文件复制到另一个目录
- hyperledger-fabric - Hyperledger Composer - 错误 8:RESOURCE_EXHAUSTED
- apache - 如何使用重写,如果第一次重写没有产生结果(在不同的位置搜索)
- linux - 如何grep多个匹配一行?
- azure-devops - 将自托管代理和 Azure 托管代理组合在同一个池中
- php - 如何使 Doctrine 在多台服务器上的结果缓存失效?
- java - 这种时间格式的模式是什么?
- swift - Firebase iOS 从推送通知接收数据