Skip to content

[subprocess] coverage and read-only site-packages #2084

@stanislavlevin

Description

@stanislavlevin

Describe the bug
Patching read-only site-packages for subprocess support fails.

To Reproduce
If coverage runs in environments where Python's site-packages are read-only the patch=subprocess feature doesn't work. Errors of creating pth files are ignored:
https://github.com/coveragepy/coveragepy/blob/main/coverage/patch.py#L156-L165

Answer the questions below:

  • What version of Python are you using?
    Python 3.13.9
  • What version of coverage.py shows the problem? The output of coverage debug sys is helpful.
-- sys -------------------------------------------------------
coverage_version: 7.11.3
coverage_module: /usr/src/.local/lib/python3/site-packages/coverage/__init__.py
core: -none-
CTracer: available from /usr/src/.local/lib/python3/site-packages/coverage/tracer.cpython-313-x86_64-linux-gnu.so
plugins.file_tracers: -none-
plugins.configurers: -none-
plugins.context_switchers: -none-
configs_attempted: /usr/src/RPM/BUILD/pyproject_installer/.coveragerc
configs_read: /usr/src/RPM/BUILD/pyproject_installer/.coveragerc
config_file: /usr/src/RPM/BUILD/pyproject_installer/.coveragerc
config_contents: b'[run]\npatch = subprocess\n'
data_file: -none-
python: 3.13.9 (main, Nov  9 2025, 20:22:19) [GCC 14.3.1 20251017 (ALT Sisyphus 14.3.1-alt2)]
platform: Linux-6.12.56-6.12-alt1-x86_64-with-glibc2.40
implementation: CPython
build: main
        Nov  9 2025 20:22:19
gil_enabled: True
executable: /usr/bin/python3
def_encoding: utf-8
fs_encoding: utf-8
pid: 2752394
cwd: /usr/src/RPM/BUILD/pyproject_installer
path: /usr/src/.local/bin
        /usr/src/RPM/BUILD/pyproject_installer/src
        /usr/lib64/python313.zip
        /usr/lib64/python3.13
        /usr/lib64/python3.13/lib-dynload
        /usr/src/.local/lib/python3/site-packages
        /usr/lib64/python3/site-packages
        /usr/lib/python3/site-packages
environment: COVERAGE_PROCESS_CONFIG = eyJjb25maWdfZmlsZXNfYXR0ZW1wdGVkIjogWyIvdXNyL3NyYy9SUE0vQ...
 COVERAGE_PROCESS_START = .coveragerc
 HOME = /usr/src
 PYTHONPATH = src
command_line: /usr/src/.local/bin/coverage debug sys
time: 2025-11-12 14:05:05
  • How to reproduce
    • install any Linux distro
    • install coverage (e.g. with pip into user sitepackages)
    • run coverage with patch = subprocess
$ coverage run --debug=patch -m pytest -vra 
Patching subprocess
Writing subprocess .pth file: '/usr/lib64/python3/site-packages/subcover_2636615.pth'
Writing subprocess .pth file: '/usr/lib/python3/site-packages/subcover_2636615.pth'
  • Actual result
    Files are not created, subprocess coverage is not measured.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions