【发布时间】:2018-10-26 11:23:19
【问题描述】:
尝试用 django 配置 pytest,该项目已经有很多不是用 pytest 编写的测试(用 unittest 编写),但我试图让它们用 pytest 运行,这样我就可以编写 pytest 测试并让它与旧测试一起工作.
我知道 pytest-django 在 django 项目的根目录中检查 manage.py 文件,但是这个项目的 manage.py 文件不在根目录中,所以我猜这就是我运行时抛出以下错误的原因pytest 但是运行 pytest 并提供特定文件是可行的。如何指定 manage.py 在哪里?因为我在documentation 中找不到这个
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.
【问题讨论】:
-
我不知道如何解决您的问题,但我认为文档会有所帮助 docs.djangoproject.com/en/2.0/topics/testing/overview
-
除非你的
manage.py中有一些特定于项目的代码,否则指定正确的 django 设置模块就足够了(通过DJANGO_SETTINGS_MODULEenv var,或通过--dsarg,或在pytest.ini)。此外,您必须确保在sys.path中找到所有项目源,仅此而已。 -
如果您的
manage.py中有一些特定于测试的代码(这不仅仅是调整设置的垫片)并且您通过python manage.py test运行测试,然后通过read this。跨度> -
你可以显式地展示你到pytest的路径:pytest-django.readthedocs.io/en/latest/… 或许你也可以这样想:pypi.org/project/pytest-pythonpath
标签: python django pytest pytest-django