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

DEV: Record coverage in subprocesses as well #2556

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/github-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,25 @@ jobs:
- name: Install pypdf
run: |
pip install .
- name: Prepare
- name: Download test files
run: |
python -c "from tests import download_test_pdfs; download_test_pdfs()"
- name: Setup sitecustomize.py for coverage
run: |
SITE_PACKAGES="$(python -m site --user-site)"
SITECUSTOMIZE_PATH="$SITE_PACKAGES/sitecustomize.py"
mkdir -p $SITE_PACKAGES
touch $SITECUSTOMIZE_PATH
echo "try:" >> $SITECUSTOMIZE_PATH
echo " import coverage" >> $SITECUSTOMIZE_PATH
echo " coverage.process_startup()" >> $SITECUSTOMIZE_PATH
echo "except ImportError:" >> $SITECUSTOMIZE_PATH
echo " pass" >> $SITECUSTOMIZE_PATH
- name: Test with pytest
run: |
python -m pytest tests --cov=pypdf --cov-append -n auto -vv
env:
COVERAGE_PROCESS_START: 'pyproject.toml'
- name: Rename coverage data file
run: mv .coverage ".coverage.$RANDOM"
- name: Upload coverage data
Expand Down
6 changes: 5 additions & 1 deletion tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the pypdf.filters module."""
import os
import shutil
import string
import subprocess
Expand Down Expand Up @@ -254,6 +255,9 @@ def test_issue_399():

@pytest.mark.enable_socket()
def test_image_without_pillow(tmp_path):
env = os.environ.copy()
env["COVERAGE_PROCESS_START"] = "pyproject.toml"

name = "tika-914102.pdf"
pdf_path = Path(__file__).parent / "pdf_cache" / name
pdf_path_str = str(pdf_path.resolve()).replace("\\", "/")
Expand Down Expand Up @@ -281,7 +285,7 @@ def test_image_without_pillow(tmp_path):
)
result = subprocess.run(
[shutil.which("python"), source_file], # noqa: S603
capture_output=True,
capture_output=True, env=env,
)
assert result.returncode == 0
assert result.stdout == b""
Expand Down