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

时间:2016-01-08 00:44:50

标签: django pytest pytest-django

我刚刚开始使用Django,并且只使用PyTest进行了几个项目,但我喜欢它们。

所以我很高兴发现 pytest-django 插件看起来非常直观且易于使用。

Per part 5 of the Django tutorial(我一直在努力),我在mysite/polls/tests.py写了一些测试。这些内置测试运行器完美运行。

所以,现在安装了 pytest pytest-django ,当我从项目根目录中运行py.test时,或py.test polls我得到了没什么:

collected 9 items

当我用py.test polls/tests.py显式调用我的文件时,我得到了丰富多彩的预期输出:

enter image description here

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

1 个答案:

答案 0 :(得分:2)

遵循pytest命名约定,尝试将测试文件重命名为: test_ [这里有些文字] .py

例如: test_polls_unittests.py

阅读有关pytest的更多信息 - 测试命名约定here

相关问题