PyTest doesn't run any test

喜欢而已 提交于 2020-08-22 04:52:51

问题


PyTest doesn't run any tests and it is not clear why. I tried to use --debug but didn't get any valuable information. 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?)

Example of test file:

$ cat test_sanity.py 
import pytest


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

    assert True

But PyTest doesn't run any test:

$ 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 ==============================================

Why so?


回答1:


To determine why tests are not running, these steps are useful:

  1. Verify that all files with test cases start with 'test_' word.
  2. Verify that all test cases names also start with 'test_' word.
  3. Verify that you have created pytest.ini file in the root directory
  4. Verify that you have __init__.py file in all directories/sub-directories of the project


来源:https://stackoverflow.com/questions/45210149/pytest-doesnt-run-any-test

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!