Run a Python script with coverage tracking and allow the user to specify the coverage data file.
Project description
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
.coveragewriting, 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
mbcsand 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file run_with_coverage-0.1.0a7.tar.gz.
File metadata
- Download URL: run_with_coverage-0.1.0a7.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
493e451aba51eca5e3080c752320ee6fc61a2360e310ac904e40d6d29a51debc
|
|
| MD5 |
3681422f78f501c3ce5437a70a624a0f
|
|
| BLAKE2b-256 |
8d728a6315212464fa6faa8fcd9c4fe985fb17804fc772c842480b9c50b64fe5
|
File details
Details for the file run_with_coverage-0.1.0a7-py2.py3-none-any.whl.
File metadata
- Download URL: run_with_coverage-0.1.0a7-py2.py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c48b50a2813c369f80fd4fe71480522a9e5b89712185061b63c5b0f098d626e
|
|
| MD5 |
75a67c87dd544f048bc7e2df5df37bdd
|
|
| BLAKE2b-256 |
39a7e0b09e75b34908dbb0a42003b850bb041891139babc7ab9715b8efe89cb9
|