Skip to content

Option for coverage lcov to ignore empty database #2054

@phst

Description

@phst

Is your feature request related to a problem? Please describe.

See bazel-contrib/rules_python#2762 for some context.
Due to the way Bazel and rules_python is set up, it can happen that coverage run is invoked so that it generates an empty .coverage database. In particular, Bazel can be instructed to only instrument certain files/directories for coverage; if these directories don't contain any Python files the coverage database will be empty. In that case, coverage lcov unconditionally fails with a NoDataError exception. This case is somewhat difficult to detect in advance.

Describe the solution you'd like
A command-line option to coverage lcov to ignore an empty database. When the option is given, coverage lcov would write an empty LCOV file and exit successfully.

Describe alternatives you've considered

  • Somehow detect the case in advance: this seems quite difficult because the coverage driver script in rules_python would need to detect whether there are any Python source files in the to-be-covered directories, effectively duplicating the work of coverage.py
  • Detect the case after the coverage run command: Would require finding and parsing the .coverage database
  • Ignoring the exit status of coverage lcov: would suppress detection of any other errors

Additional context
bazel-contrib/rules_python#2762

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions