pytest-django 不会发现我的测试,除非明确调用

pytest-django doesn't discover my tests, unless explicitly invoked

我刚开始使用 Django,并且只在几个项目中使用过 PyTest,但我都喜欢它们。

所以我很高兴发现 pytest-django 插件,它看起来非常简单易用。

根据 part 5 of the Django tutorial(我一直在努力),我在 mysite/polls/tests.py 中编写了一些测试。这些 运行 与内置测试 运行ner 完美结合。

所以,现在安装了 pytestpytest-django,当我从内部 运行 py.test项目根目录,或者 py.test polls 我一无所获:

当我使用 py.test polls/tests.py 显式调用我的文件时,我得到了五颜六色的预期输出:

我错过了什么?我严格按照设置进行操作,插件的 Basic Usage docs 证明一个简单的 py.test 应该会自动找到我的测试。为什么他们没有被发现?

按照 pytest 命名约定,尝试将您的测试文件重命名为: test_[这里有一些文字].py

例如: test_polls_unittests.py

详细了解 pytest - 测试命名约定 here