From 7b99d4512c03da3f53217f59b413023eee44aa28 Mon Sep 17 00:00:00 2001 From: Stefan <96178532+stefan6419846@users.noreply.github.com> Date: Fri, 29 Mar 2024 18:30:21 +0100 Subject: [PATCH 1/3] DEV: Record coverage in subprocesses as well --- .github/workflows/github-ci.yaml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/github-ci.yaml b/.github/workflows/github-ci.yaml index 820ccdcaa..3e5abaa9a 100644 --- a/.github/workflows/github-ci.yaml +++ b/.github/workflows/github-ci.yaml @@ -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 From fd83294e24a4faf49c8e68a827ef51392e5d2c38 Mon Sep 17 00:00:00 2001 From: Stefan <96178532+stefan6419846@users.noreply.github.com> Date: Fri, 29 Mar 2024 19:04:25 +0100 Subject: [PATCH 2/3] attempt to pass env directly --- tests/test_filters.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_filters.py b/tests/test_filters.py index 6edd4c513..a5b970971 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -1,4 +1,5 @@ """Test the pypdf.filters module.""" +import os import shutil import string import subprocess @@ -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("\\", "/") @@ -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"" From fb5c2f1f4f7e0a740ca6502603c1821d1419dcbc Mon Sep 17 00:00:00 2001 From: Stefan <96178532+stefan6419846@users.noreply.github.com> Date: Sun, 28 Jul 2024 16:45:12 +0200 Subject: [PATCH 3/3] use latest coverage package --- requirements/ci-3.11.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/ci-3.11.txt b/requirements/ci-3.11.txt index f382fe2b9..971d5584f 100644 --- a/requirements/ci-3.11.txt +++ b/requirements/ci-3.11.txt @@ -6,7 +6,7 @@ # attrs==23.1.0 # via flake8-bugbear -coverage[toml]==7.3.0 +coverage[toml]==7.6.0 # via # -r requirements/ci.in # pytest-cov