Skip to content

Commit 2de083f

Browse files
phstaignas
andauthored
fix(coverage): Disable certain coverage warnings. (#3191)
These warnings appear if there are no Python source files in the instrumented directories, cf. #2762. Work towards #2762 --------- Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
1 parent a1ca5d4 commit 2de083f

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ END_UNRELEASED_TEMPLATE
6262

6363
{#v0-0-0-fixed}
6464
### Fixed
65-
* Nothing fixed.
65+
* (tests) No more coverage warnings are being printed if there are no sources.
66+
([#2762](https://github.com/bazel-contrib/rules_python/issues/2762))
6667

6768
{#v0-0-0-added}
6869
### Added

python/private/py_executable.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,7 @@ def _create_stage2_bootstrap(
668668
template = template,
669669
output = output,
670670
substitutions = {
671+
"%coverage_instrumented%": str(int(ctx.configuration.coverage_enabled and ctx.coverage_instrumented())),
671672
"%coverage_tool%": _get_coverage_tool_runfiles_path(ctx, runtime),
672673
"%import_all%": "True" if read_possibly_native_flag(ctx, "python_import_all_repositories") else "False",
673674
"%imports%": ":".join(imports.to_list()),

python/private/stage2_bootstrap_template.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
# string otherwise.
4242
VENV_SITE_PACKAGES = "%venv_rel_site_packages%"
4343

44+
# Whether we should generate coverage data.
45+
COVERAGE_INSTRUMENTED = "%coverage_instrumented%" == "1"
46+
4447
# ===== Template substitutions end =====
4548

4649

@@ -319,11 +322,14 @@ def _maybe_collect_coverage(enable):
319322
# We need for coveragepy to use relative paths. This can only be configured
320323
# using an rc file.
321324
rcfile_name = os.path.join(coverage_dir, ".coveragerc_{}".format(unique_id))
325+
disable_warnings = ('disable_warnings = module-not-imported, no-data-collected'
326+
if COVERAGE_INSTRUMENTED else '')
322327
print_verbose_coverage("coveragerc file:", rcfile_name)
323328
with open(rcfile_name, "w") as rcfile:
324329
rcfile.write(
325330
f"""[run]
326331
relative_files = True
332+
{disable_warnings}
327333
source =
328334
\t{source}
329335
"""

0 commit comments

Comments
 (0)