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

Feature request: A new [run] source_dirs configuration option #1942

Closed
jfly opened this issue Mar 27, 2025 · 6 comments
Closed

Feature request: A new [run] source_dirs configuration option #1942

jfly opened this issue Mar 27, 2025 · 6 comments
Labels
enhancement New feature or request

Comments

@jfly
Copy link
Contributor

jfly commented Mar 27, 2025

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

The existing [run] source option is ambiguous: it can contain either directories or package names, and we deduce at runtime which is which based on if they are actually a directory or not: https://github.com/nedbat/coveragepy/blob/7.7.1/coverage/inorout.py#L198-L201.

This results in quirky bugs like this one for coverage.py where something treated as a directory can change into getting treated as a package in a subprocess. This particular bug is fixable without changing coveragepy, but the fix would be cleaner if we had an explicit, unambiguous mechanism for specifying source directories. Ideally coveragepy would then error out if these directories don't exist, which would make bugs like pytest-dev/pytest-cov#465 even less likely.

Describe the solution you'd like

We already have a [run] source_pkgs option that lets you unambiguously specify package names, I'd like a corresponding [run] source_dirs option.

Describe alternatives you've considered

The status quo: don't add this feature. Hopefully I've justified it sufficiently above.

@jfly jfly added the enhancement New feature or request label Mar 27, 2025
jfly added a commit to jfly/pytest-cov that referenced this issue Mar 27, 2025
This `COV_CORE_SOURCE` environment variable is key for making sure that
child processes continue computing code coverage. However, there's no
guarantee that child processes start in the same directory as their parent
process, which screws up coverage reporting if you're using relative
paths for coverage sources. The fix is to make sure we're dealing with
absolute paths.

This is a little tricky to get right, because sources can include both
dirs and packages.

This fixes nedbat/coveragepy#1942.
@jfly
Copy link
Contributor Author

jfly commented Mar 27, 2025

Urg, sorry. Please ignore pytest-dev/pytest-cov#681. It's a fix for a bug related to this issue, but doesn't fix this issue.

@nedbat
Copy link
Owner

nedbat commented Mar 27, 2025

This sounds like a reasonable idea.

@jfly
Copy link
Contributor Author

jfly commented Mar 27, 2025

@nedbat, awesome! I'll try to put together a PR for this.

jfly added a commit to jfly/coveragepy that referenced this issue Mar 27, 2025
@jfly
Copy link
Contributor Author

jfly commented Mar 27, 2025

PR out for review here: #1943

jfly added a commit to jfly/coveragepy that referenced this issue Mar 27, 2025
jfly added a commit to jfly/coveragepy that referenced this issue Mar 27, 2025
nedbat pushed a commit that referenced this issue Mar 28, 2025
@jfly
Copy link
Contributor Author

jfly commented Mar 28, 2025

Closing. This was implemented in #1943

@jfly jfly closed this as completed Mar 28, 2025
@nedbat
Copy link
Owner

nedbat commented Mar 30, 2025

This is now released as part of coverage 7.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants