Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a single test method with pytest fails (not found)

I am trying to run a specific test method with pytest on Python 3.6 with the following command:

pytest sanity_test.py::test_check

(as mentioned in pytest docs)

and it fails with the following error message:

ERROR: not found: <rootdir>/tests/automation/sanity/sanity_test.py::test_check
(no name '<rootdir>/tests/automation/sanity/sanity_test.py::test_check' in any of [<DoctestModule 'tests/automation/sanity/sanity_test.py'>, <Module 
'tests/automation/sanity/sanity_test.py'>])

when I run the whole test file the tests are running properly with:

pytest sanity_test.py

When I tried running a specific method in isolated project it works perfectly.

Any reason why pytest can't find specifically my test methods on my project?

The file is very simple and looks like this:

def test_check():
    pass
like image 957
Matan Bakshi Avatar asked Aug 20 '18 12:08

Matan Bakshi


People also ask

What does pytest fail do?

If you call pytest. fail inside a test, it's a FAIL status for that test (or XFAIL, if it has xfail mark). But, if you call it from a fixture, the test, which depends on this fixture, is getting ERROR state.

How do I run multiple tests in pytest?

Run Multiple Tests From a Specific File and Multiple Files To run all the tests from all the files in the folder and subfolders we need to just run the pytest command. This will run all the filenames starting with test_ and the filenames ending with _test in that folder and subfolders under that folder.

How do I ignore a test in pytest?

The simplest way to skip a test function is to mark it with the skip decorator which may be passed an optional reason : @pytest. mark. skip(reason="no way of currently testing this") def test_the_unknown(): ...


1 Answers

Thank to hoefling, I recognized that I had --doctest-modules option in my setup.cfg file. Removing this option fixed the problem. hoefling opened an issue in pytest for that problem.

like image 89
Matan Bakshi Avatar answered Nov 11 '22 09:11

Matan Bakshi