'pytest' exits with no error, but with "collected 0 items"

I had the same issue, but my function was called test.py. I never thought that the issue would be the file name.

In the documentation it says:

pytest will run all files of the form test_*.py or *_test.py in the current directory and its subdirectories. More generally, it follows standard test discovery rules.

Exactly! The name should be test_.py or test_something.py and works for me.

I feel so stupid, hehe.


pytest gathers tests according to a naming convention. By default any file that is to contain tests must be named starting with test_, classes that hold tests must be named starting with Test, and any function in a file that should be treated as a test must also start with test_.

If you rename your test file to test_sorts.py and rename the example function you provide above as test_integer_sort, then you will find it is automatically collected and executed.

This test collecting behavior can be changed to suit your desires. Changing it will require learning about configuration in pytest.