Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Run With Coverage

Run a Python script with coverage tracking, allowing the user to specify the coverage data file - even in complex or non-standard environments.

  • ✅ Python 2 & 3 compatible
  • ✅ Windows & POSIX support
  • ✅ Unicode-safe, including non-ASCII paths
  • ✅ Safe .coverage writing, even when filenames contain spaces or non-UTF-8 characters
  • ✅ Temp file management compatible with SQLite's UTF-8-only file requirements

Fun Fact: The basic Unix implementation took 1 day. Windows compatibility took 14. You're welcome.

Installation

pip install run-with-coverage

After installation, run it as run_with_coverage.

Why This Exists

Most test runners (pytest, nose, etc.) and coverage tools (coverage.py) make assumptions:

  • Filenames are UTF-8 or ASCII
  • Paths don't contain spaces or non-English characters
  • Python 3 is the only target platform
  • subprocess is sufficient for launching scripts

These assumptions break in:

  • Internationalized environments (e.g. Chinese, Japanese, Cyrillic filenames)
  • Enterprise and legacy systems still running Python 2
  • Windows, where environment variables use mbcs and temp file encoding matters

Usage

run_with_coverage [-c <coverage_file>] [-v] [-L] -- <script_to_run> [args...]
  • -c: Coverage output file (default: .coverage)
  • -v: Enable verbose logging
  • -L: Measure library code
  • --: Required delimiter to separate runner options from the script being tested

Example: Running on Windows with Non-ASCII Paths

This example runs a Python script in a Unicode path with arguments, saving the coverage file to a Unicode path as well.

Example script under test C:\Users\Administrator\Desktop\路径 有空格\名字 有空格.py:

# coding=utf-8
from __future__ import print_function
import sys

for i, arg in enumerate(sys.argv):
    print('sys.argv[%d]=%s' % (i, arg))

Example command:

C:\Users\jifengwu2k\packages\run-with-coverage>run_with_coverage -c "..\..\路径 有空格\输出 文件.sqlite3" -v -- "..\..\路径 有空格\名字 有空 格.py" 参数1 "参数2 有空格"

Sample output:

2025-06-21 14:47:28,516 - DEBUG - Preparing to run script with coverage.
2025-06-21 14:47:28,516 - DEBUG - Script path: C:\Users\jifengwu2k\路径 有空格\名字 有空格.py
2025-06-21 14:47:28,516 - DEBUG - Arguments: [u'\u53c2\u65701', u'\u53c2\u65702 \u6709\u7a7a\u683c']
2025-06-21 14:47:28,516 - DEBUG - Coverage output path: C:\Users\jifengwu2k\路径 有空格\输出 文件.sqlite3
2025-06-21 14:47:28,517 - DEBUG - Temporary file for coverage created at: C:\Windows\Temp\tmphulafg
2025-06-21 14:47:28,517 - DEBUG - Launching process:
sys.argv[0]=C:\Users\jifengwu2k\路径 有空格\名字 有空格.py
sys.argv[1]=参数1
sys.argv[2]=参数2 有空格
2025-06-21 14:47:28,678 - INFO - Script exited with code: 0
2025-06-21 14:47:28,680 - DEBUG - Moving temp coverage file to final destination: C:\Users\jifengwu2k\路径 有空格\输出 文件.sqlite3

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

Release files for run-with-coverage 0.1.0a7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for run-with-coverage 0.1.0a7
File Size Uploaded
run_with_coverage-0.1.0a7.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for run-with-coverage 0.1.0a7
File Interpreter ABI Platform
run_with_coverage-0.1.0a7-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 12.0 kB

Release files / run_with_coverage-0.1.0a7.tar.gz

Download URL run_with_coverage-0.1.0a7.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
493e451aba51eca5e3080c752320ee6fc61a2360e310ac904e40d6d29a51debc
BLAKE2b-256 checksum
How to use checksums
8d728a6315212464fa6faa8fcd9c4fe985fb17804fc772c842480b9c50b64fe5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release files / run_with_coverage-0.1.0a7-py2.py3-none-any.whl

Download URL run_with_coverage-0.1.0a7-py2.py3-none-any.whl
Size 6.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9c48b50a2813c369f80fd4fe71480522a9e5b89712185061b63c5b0f098d626e
BLAKE2b-256 checksum
How to use checksums
39a7e0b09e75b34908dbb0a42003b850bb041891139babc7ab9715b8efe89cb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.1.0a7 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page