简体   繁体   English

pytest 不运行任何测试

[英]pytest doesn't run any test

pytest doesn't run any tests and it is not clear why. pytest 没有运行任何测试,原因尚不清楚。 I tried to use --debug but didn't get any valuable information.我尝试使用 --debug 但没有得到任何有价值的信息。 It is completely not clear how to debug this sort of issues with pytest. (Looks like some issue with pytest configuration / env variables / test names patterns?)完全不清楚如何使用 pytest 调试此类问题。(看起来像 pytest 配置/环境变量/测试名称模式的一些问题?)

Example of test file:测试文件示例:

import pytest


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

    assert True

But pytest doesn't run any test, why?但是 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 ==============================================

To determine why tests are not running, these steps are useful:要确定测试未运行的原因,以下步骤很有用:

  1. Verify that all files with test cases start with 'test_' word.验证所有包含测试用例的文件都以“test_”字开头。
  2. Verify that all test cases names also start with 'test_' word.验证所有测试用例名称是否也以“test_”字开头。
  3. Verify that you have created pytest.ini file in the root directory.验证您是否已在根目录中创建了pytest.ini文件。
  4. Verify that you have __init__.py file in all directories/sub-directories of the project.验证您在项目的所有目录/子目录中都有__init__.py文件。

You need all tests to start with test_ but also you need to tell Pytest exact which files to look for:您需要所有测试都以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