I would like to ensure that for each implemented function in my code base there is a corresponding unit test.
def top_level_function():
sub_function()
def sub_function()
print('hello')
If I forget to patch/mock a sub function call, the original sub function will be used. The test coverage will be 100 %, even if there is no unit test for the sub function.
=> Test coverage is not a sufficient parameter to find out if there are enough unit tests.
=> How can I find out if the functions
a) are called by their corresponding unit tests (as should) or
b) if they are called by a "parent functions" (want to avoid that during testing)?
Maybe there is an additional pytest package to do so or some setting of pytest-cov to report missing unit tests? I could not find it, yet.
(I want a unit test for top_level_function
only to fail if the corresponding function fails.
It should not fail if there is a bug in a sub function sub_function
. Therefore, I usually mock the sub function calls when testing a function.)
Edit
I. Here is a pytest plugin that looked promising:
https://pypi.org/project/pytest-func-cov/
However, it does not seem to work, see open issue
=> Is there some alternative plugin that does work?
II. The PyCharm plugin Pycrunch allows to show what lines of code are covered by what unit test.
That does not resolve my problem but helps to identify lines that are not covered correctly.