I have the following project (available on GitHub):
Here's test_some_unit.py
:
from ..util.foo import run_foo
def test_some_unit():
run_foo()
print("Unit test")
Running discovery for test.unit
produces 0 tests:
python -m unittest discover test.unit
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Why?
Your test cases are module-level functions. pytest
supports test cases written in that way, but unittest
doesn't. In unittest
, test cases are methods of test classes (which inherit from unittest.TestCase
). (Reference: "Organizing test code" in module documentation).
So you would need to reorganize your tests into this style for them to be discovered.