Python flask project missing files in sonarqube

i have a python flask project where i am using the below commands to run test cases and get coverage report
pytest tests/ --cov=. --cov-report xml:coverage.xml
coverage report -m

My flask api project folder looks like below
app.py
folder_A/api.py
folder_B/file2.py
folder_C/folder_D/file3.py
conftest.py
tests/testcases.py

I have conftest.py which uses pytest.fixture() and a flask client for the flaskapi.

My conftest.py looks like below

@pytest.fixture()
def client():
    app = connexion.FlaskApp(
        __name__, specification_dir=os.path.join("swagger"))
    app.add_api('openapi.yaml', validate_responses=True,
                strict_validation=True)
    with app.app.test_client() as c:
        yield c

I have written multiple test cases which hits the api using the client created in the conftest class. Even though the api.py file calls other functions in file2.py, file3.py etc. In the coverage report , I can only see the api.py file with 100%. other files in the subfolders like folder_D are not showing up in the coverage report.

Any idea on why the other python files are missing in the sonarqube,
Thanks.

Hey there.

SonarQube only reads coverage reports, it’s not involved in producing them. So the best first debugging step would be to actually look at the coverage.xml file being produced – is it reporting coverage on files in subfolders like folder_D?

hi,
Thanks for the reply. I think i found the issue. The python subfolders is missing init.py files. Eventhough this is not used in higher versions of python, the coverage command has some limitations.
This is a limitation of coverage.py - as soon as it discovers a directory without an __init__.py file, it stops recursing (from your example, you do not seem to have any __init__.py files.

Thanks.