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

Ensure source dirs are absolute #681

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/pytest_cov/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,17 @@ def set_env(self):
if self.cov_source is None:
os.environ['COV_CORE_SOURCE'] = os.pathsep
else:
os.environ['COV_CORE_SOURCE'] = os.pathsep.join(self.cov_source)
os.environ['COV_CORE_SOURCE'] = os.pathsep.join(
# We must make the paths absolute to ensure that subprocesses started in different
# directories still find the same sources: https://github.com/nedbat/coveragepy/issues/1942.
# Unfortunately, coverage.py doesn't provide a mechanism
# for unambiguously specifying source_dirs, so we have to detect if a source is
# a directory or a package by looking in the filesystem: https://github.com/nedbat/coveragepy/issues/1942.
os.path.abspath(source) # noqa: PTH100 # see note below for why we're using `os.path.abspath`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the note below?

Copy link
Author

@jfly jfly Apr 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://github.com/pytest-dev/pytest-cov/blob/v6.1.0/src/pytest_cov/engine.py#L120-L121. Happy to remove this if it's no longer applicable.

if Path(source).is_dir()
else source
for source in self.cov_source
)
config_file = Path(self.cov_config)
if config_file.exists():
os.environ['COV_CORE_CONFIG'] = os.fspath(config_file.resolve())
Expand Down