Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Run Test with Coverage" should catch NoSource exceptions #24308

Open
bersbersbers opened this issue Oct 15, 2024 · 5 comments
Open

"Run Test with Coverage" should catch NoSource exceptions #24308

bersbersbers opened this issue Oct 15, 2024 · 5 comments
Assignees
Labels
feature-request Request for new features or functionality triage-needed Needs assignment to the proper sub-team

Comments

@bersbersbers
Copy link

The root cause of my observations in #24307 (which still deserves its own solution IMHO) is nedbat/coveragepy#1392. Unfortunately, configuring omit alone does not help because this code snipped does not consider it:

# load the report and build the json result to return
import coverage
cov = coverage.Coverage()
cov.load()
file_set: set[str] = cov.get_data().measured_files()
file_coverage_map: dict[str, FileCoverageInfo] = {}
for file in file_set:
analysis = cov.analysis2(file)
lines_executable = {int(line_no) for line_no in analysis[1]}
lines_missed = {int(line_no) for line_no in analysis[3]}
lines_covered = lines_executable - lines_missed
file_info: FileCoverageInfo = {
"lines_covered": list(lines_covered), # list of int
"lines_missed": list(lines_missed), # list of int
}
file_coverage_map[file] = file_info

cov._check_include_omit_etc being private, the extension cannot really know what to check. So I propose replacing

analysis = cov.analysis2(file)

by

try:
    analysis = cov.analysis2(file)
except NoSource:
    continue
@bersbersbers bersbersbers added the feature-request Request for new features or functionality label Oct 15, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Oct 15, 2024
@bersbersbers
Copy link
Author

There may be better solutions still. E.g., Coverage() takes an omit parameter that may help:

cov = coverage.Coverage()

Compare also #24309

@eleanorjboyd
Copy link
Member

How are you listing omitted files? Omitting seems to be something I need to explore in general as I have gotten a few comments related to this. How does your issue compare to #24366? It seems your ask is less about the UI including or not including and more about if the run works due to files you need to skip?

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Oct 30, 2024
@bersbersbers
Copy link
Author

bersbersbers commented Oct 31, 2024

At its core, this issue is not about omitting files. Being able to omit files (either during run [which is currently possible via the coverage configuration] or report [which is not currently possible], compare #24309 (comment)) would be one workaround for this issue, but it's a different problem altogether.

In this issue, I care about error handling during the reporting phase, in case a file that existed during run is missing during report. This happens when a Python library unpacks code at runtime, only to delete these files when done. See nedbat/coveragepy#1392 (comment) for one example. These files will then be missing during the reporting phase, leading to errors in the VS Code extension.

This can happen for other reasons, too - e.g., when processing coverage results after uninstalling a Python library. So I would argue that the extension should catch NoSource extensions under all circumstances.

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Oct 31, 2024
@bersbersbers
Copy link
Author

bersbersbers commented Oct 31, 2024

It seems your ask is less about the UI including or not including and more about if the run works due to files you need to skip?

Yes, correct.

@eleanorjboyd
Copy link
Member

Thank you for the clarification! I will look into this now I understand the whole premise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants