繁体   English   中英

pytest 不运行任何测试

[英]pytest doesn't run any test

pytest 没有运行任何测试,原因尚不清楚。 我尝试使用 --debug 但没有得到任何有价值的信息。 完全不清楚如何使用 pytest 调试此类问题。(看起来像 pytest 配置/环境变量/测试名称模式的一些问题?)

测试文件示例:

import pytest


@pytest.mark.sanity
def test_me():
    """I'm a test."""

    assert True

但是 pytest 没有运行任何测试,为什么?

$ pytest
================================================== test session starts ===================================================
platform linux2 -- Python 2.7.12, pytest-3.1.3, py-1.4.34, pluggy-0.4.0
rootdir: /home/qawizard/pytest-hell, inifile:
plugins: xdist-1.15.0, timeout-1.2.0
collected 1 item s

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Exit: Done! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================== no tests ran in 0.13 seconds ==============================================

要确定测试未运行的原因,以下步骤很有用:

  1. 验证所有包含测试用例的文件都以“test_”字开头。
  2. 验证所有测试用例名称是否也以“test_”字开头。
  3. 验证您是否已在根目录中创建了pytest.ini文件。
  4. 验证您在项目的所有目录/子目录中都有__init__.py文件。

您需要所有测试都以test_开头,但您还需要告诉 Pytest 确切要查找的文件:

# pytest.ini

[pytest]

DJANGO_SETTIONS_MODULE = myproject.settings
python_files = tests.py test_*.py

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM