False positives on empty __init__.py

While python 3 no longer require the presence of empty __init__.py files to resolve modules imports, the new behavior is not yet supported by all the tools around python (green for example).

As such we are still including empty __init__.py as part of our python package structure. Unfortunately we get false positives such as missing docstrings, missing line or branch coverage.

To reproduce simply add empty __init__.py files to an existing python3 project and observe the issues.

While it is pretty simple to resolve these as false positive, they should not show up in the first place and Sonar should be mostly ignoring empty __init__.py files.

We do have a few __init__.py files that have actual lines of python and we want the general rules to apply to these, so the exclusion is really only for empty files.


Hi @sodul,

Thanks a lot for reporting this: I agree we should treat those empty __init__.py files specially.

This might indeed be a possible solution, however for the time being I created the following tickets:

Could you please tell me if you noticed other rules raising FPs on those files?


1 Like

I thinks that’s all of it.

On the coverage front it might be possible that the rule comes in place if there are only comments and a docstring … I took a quick look and could not find a recent sonar report with the coverage issue but I’ve had complaints about that in the past.

The docstring rule is definitely triggered.

1 Like

I confirmed today that we had a new empty init.py script that was flagged as lacking coverage.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.