I am testing my code with pytest --cov but one of my modules gets 0% coverage.
The module has one class declaration as such:
class DataBaseMaker:
@staticmethod
def create_database():
conn = sqlite3.connect("database.db")
def __init__(self):
self.foo = 'bar'
The test does the following:
def test_create_database():
DataBaseMaker.create_database()
assert Path("database.db").is_file()
Test coverage for this is 0% - what am I doing wrong here?
I was able to find out what the issue is. It was not with the code itself but with my invocation of pytest. I did pytest --cov *projectname*
where projectname was also the name of the folder the project is in. I think I got this from the pytest documentation? Not sure.
The solution: I ran pytest --cov .
and sure enough my classes have 100% coverage now. If someone has an explanation for that behavior I'd be happy to learn.