mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-02-27 18:59:42 +00:00
[test] Add code coverage framework
Implement a comprehensive test coverage framework that integrates with pytest-cov to generate code coverage reports for the yt-dlp codebase. Key components: - Configuration file (.coveragerc) with appropriate include/exclude patterns - Helper script (run_coverage.py) with parallel report generation - GitHub Actions workflow for automatic coverage reporting on PRs and pushes - Support for Hatch testing environment and CLI integration - Testing documentation for running coverage reports - Sample test for demonstrating coverage reporting
This commit is contained in:
66
.github/workflows/coverage.yml
vendored
Normal file
66
.github/workflows/coverage.yml
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
name: Code Coverage
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
coverage:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
cache: pip
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -e ".[dev]"
|
||||
pip install pytest-cov
|
||||
|
||||
- name: Run coverage tests in parallel
|
||||
run: |
|
||||
# Create a simple script to run coverage tests in parallel
|
||||
cat > run_parallel_coverage.py << 'EOF'
|
||||
import concurrent.futures
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def run_coverage(args):
|
||||
test_path, module_path = args
|
||||
cmd = ['python', '-m', 'devscripts.run_coverage', test_path, module_path]
|
||||
return subprocess.run(cmd, check=True)
|
||||
|
||||
coverage_tests = [
|
||||
('test/test_utils.py', 'yt_dlp.utils'),
|
||||
('test/test_YoutubeDL.py', 'yt_dlp.YoutubeDL'),
|
||||
('test/devscripts', 'devscripts')
|
||||
]
|
||||
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
|
||||
futures = [executor.submit(run_coverage, test) for test in coverage_tests]
|
||||
for future in concurrent.futures.as_completed(futures):
|
||||
try:
|
||||
future.result()
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error running coverage: {e}")
|
||||
sys.exit(1)
|
||||
EOF
|
||||
|
||||
# Run the script
|
||||
python run_parallel_coverage.py
|
||||
|
||||
- name: Archive coverage results
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: coverage-report
|
||||
path: |
|
||||
.coverage-reports/html/
|
||||
.coverage-reports/coverage.xml
|
||||
Reference in New Issue
Block a user