Skip to content

Commit

Permalink
DEV: Record coverage in subprocesses as well (#2556)
Browse files Browse the repository at this point in the history
* DEV: Record coverage in subprocesses as well

* attempt to pass env directly

* use latest coverage package

* do not copy environment twice

---------

Co-authored-by: pubpub-zz <[email protected]>
  • Loading branch information
stefan6419846 and pubpub-zz authored Dec 25, 2024
1 parent 6d4e2ec commit ddc23bb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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
8 changes: 5 additions & 3 deletions 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 @@ -257,11 +258,12 @@ def test_issue_399():

@pytest.mark.enable_socket
def test_image_without_pillow(tmp_path):
import os
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("\\", "/")
pdf_path_str = pdf_path.resolve().as_posix()

source_file = tmp_path / "script.py"
source_file.write_text(
Expand All @@ -284,7 +286,7 @@ def test_image_without_pillow(tmp_path):
), exc.value.args[0]
"""
)
env = os.environ.copy()

try:
env["PYTHONPATH"] = "." + os.pathsep + env["PYTHONPATH"]
except KeyError:
Expand Down

0 comments on commit ddc23bb

Please sign in to comment.