Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytest doesn't run any test

Tags:

python

pytest

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:

import pytest


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

    assert True

But pytest doesn't run any test, why?

$ 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 ==============================================
like image 295
Timur Nurlygayanov Avatar asked Jul 20 '17 09:07

Timur Nurlygayanov


People also ask

Does pytest run tests sequentially?

pytest-ordering is a pytest plugin to run your tests in any order that you specify. It provides custom markers that say when your tests should run in relation to each other. They can be absolute (i.e. first, or second-to-last) or relative (i.e. run this test before this other test).

Is pytest deprecated?

The pytest.Deprecated since version 6.0. The pytest. collect module is no longer part of the public API, all its names should now be imported from pytest directly instead.


1 Answers

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.
like image 96
Timur Nurlygayanov Avatar answered Oct 19 '22 23:10

Timur Nurlygayanov