【问题标题】:pytest-django doesn't discover my tests, unless explicitly invokedpytest-django 不会发现我的测试,除非显式调用
【发布时间】:2016-04-12 14:06:39
【问题描述】:

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

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

根据part 5 of the Django tutorial(我一直在努力),我已经在mysite/polls/tests.py 中编写了许多测试。这些可以通过内置的测试运行器完美运行。

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

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

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

【问题讨论】:

    标签: django pytest pytest-django


    【解决方案1】:

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

    例如: test_polls_unittests.py

    阅读更多关于 pytest - 测试命名约定here

    【讨论】:

    • 这非常有效。将tests.py 重命名为test_polls.py,现在所有这些都可以通过py.test 命令自动检测和运行。谢谢!
    • 耶!很高兴听到:)
    • 或者,您可以将python_files = tests.py test_*.py 添加到项目的pytest.ini 文件的[pytest] 部分。请参阅问题pytest-django/#67related pytest docs
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多