From dd7cfdc641e30302c033baba8ecb03c4ed119739 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 25 May 2025 23:26:33 +0300 Subject: [PATCH 1/7] Run tests in parallel with pytest-xdist --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f4514925d1c..db24747523c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,6 +73,7 @@ optional-dependencies.tests = [ "pyroma>=5", "pytest", "pytest-cov", + "pytest-sugar", "pytest-timeout", "pytest-xdist", "trove-classifiers>=2024.10.12", @@ -208,7 +209,7 @@ lint.isort.required-imports = [ max_supported_python = "3.14" [tool.pytest.ini_options] -addopts = "-ra --color=auto" +addopts = "-ra --color=auto --numprocesses=auto" testpaths = [ "Tests", ] From a5b3e85696ebbb010118a27d2827fa38dbfa25d1 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 27 Jun 2025 16:01:03 +0300 Subject: [PATCH 2/7] Install with tests extra --- .ci/build.sh | 1 - .ci/install.sh | 7 ------- .github/workflows/test-mingw.yml | 2 +- Makefile | 2 +- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index ae10cb67155..c172e513f68 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -2,6 +2,5 @@ set -e -python3 -m coverage erase make clean make install-coverage diff --git a/.ci/install.sh b/.ci/install.sh index aeb5e65145d..30590449dda 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -24,14 +24,7 @@ sudo apt-get -qq install libfreetype6-dev liblcms2-dev libtiff-dev python3-tk\ python3 -m pip install --upgrade pip python3 -m pip install --upgrade wheel -python3 -m pip install coverage -python3 -m pip install defusedxml python3 -m pip install ipython -python3 -m pip install olefile -python3 -m pip install -U pytest -python3 -m pip install -U pytest-cov -python3 -m pip install -U pytest-timeout -python3 -m pip install pyroma # optional test dependencies, only install if there's a binary package. python3 -m pip install --only-binary=:all: numpy || true python3 -m pip install --only-binary=:all: pyarrow || true diff --git a/.github/workflows/test-mingw.yml b/.github/workflows/test-mingw.yml index e247414c8fc..baf0d1373fb 100644 --- a/.github/workflows/test-mingw.yml +++ b/.github/workflows/test-mingw.yml @@ -78,7 +78,7 @@ jobs: pushd depends && ./install_extra_test_images.sh && popd - name: Build Pillow - run: CFLAGS="-coverage" python3 -m pip install . + run: CFLAGS="-coverage" python3 -m pip install .[tests] - name: Test Pillow run: | diff --git a/Makefile b/Makefile index 6e050c715d2..b4456437174 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ install: .PHONY: install-coverage install-coverage: - CFLAGS="-coverage -Werror=implicit-function-declaration" python3 -m pip -v install . + CFLAGS="-coverage -Werror=implicit-function-declaration" python3 -m pip -v install .[tests] python3 selftest.py .PHONY: debug From 48f4693d00c0747b9839ad0b2eb338d9942bb2bd Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 14 Dec 2025 18:10:39 +0200 Subject: [PATCH 3/7] Disable xdist for valgrind Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- .github/workflows/test-valgrind-memory.yml | 7 ++++++- .github/workflows/test-valgrind.yml | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-valgrind-memory.yml b/.github/workflows/test-valgrind-memory.yml index bd244aa5a57..66ecac4bda8 100644 --- a/.github/workflows/test-valgrind-memory.yml +++ b/.github/workflows/test-valgrind-memory.yml @@ -56,5 +56,10 @@ jobs: run: | # The Pillow user in the docker container is UID 1001 sudo chown -R 1001 $GITHUB_WORKSPACE - docker run --name pillow_container -e "PILLOW_VALGRIND_TEST=true" -v $GITHUB_WORKSPACE:/Pillow pythonpillow/${{ matrix.docker }}:${{ matrix.dockerTag }} /Pillow/depends/docker-test-valgrind-memory.sh + docker run --name pillow_container \ + -e "PILLOW_VALGRIND_TEST=true" \ + -e "PYTEST_ADDOPTS=-n0" \ + -v $GITHUB_WORKSPACE:/Pillow \ + pythonpillow/${{ matrix.docker }}:${{ matrix.dockerTag }} \ + bash -c "python3 -m pip install pytest-xdist && /Pillow/depends/docker-test-valgrind-memory.sh" sudo chown -R runner $GITHUB_WORKSPACE diff --git a/.github/workflows/test-valgrind.yml b/.github/workflows/test-valgrind.yml index 81cfb84566c..6fe4935e8db 100644 --- a/.github/workflows/test-valgrind.yml +++ b/.github/workflows/test-valgrind.yml @@ -54,5 +54,9 @@ jobs: run: | # The Pillow user in the docker container is UID 1001 sudo chown -R 1001 $GITHUB_WORKSPACE - docker run --name pillow_container -e "PILLOW_VALGRIND_TEST=true" -v $GITHUB_WORKSPACE:/Pillow pythonpillow/${{ matrix.docker }}:${{ matrix.dockerTag }} + docker run --name pillow_container \ + -e "PILLOW_VALGRIND_TEST=true" \ + -e "PYTEST_ADDOPTS=-n0" \ + -v $GITHUB_WORKSPACE:/Pillow \ + pythonpillow/${{ matrix.docker }}:${{ matrix.dockerTag }} sudo chown -R runner $GITHUB_WORKSPACE From 8a124703773442b09157bf07050bc8f54d0b9e2a Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 14 Dec 2025 21:15:40 +0200 Subject: [PATCH 4/7] Remove pytest-reverse --- .ci/test.sh | 2 +- .github/workflows/test.yml | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.ci/test.sh b/.ci/test.sh index 87a605d84be..65ae84255cc 100755 --- a/.ci/test.sh +++ b/.ci/test.sh @@ -4,4 +4,4 @@ set -e python3 -c "from PIL import Image" -python3 -bb -m pytest -vv -x -W always --cov PIL --cov Tests --cov-report term --cov-report xml Tests $REVERSE +python3 -bb -m pytest -vv -x -W always --cov PIL --cov Tests --cov-report term --cov-report xml Tests diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index da3eea06641..d22484dfcb0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,7 +53,7 @@ jobs: "3.10", ] include: - - { python-version: "3.12", PYTHONOPTIMIZE: 1, REVERSE: "--reverse" } + - { python-version: "3.12", PYTHONOPTIMIZE: 1 } - { python-version: "3.11", PYTHONOPTIMIZE: 2 } # Free-threaded - { python-version: "3.15t", disable-gil: true } @@ -123,9 +123,6 @@ jobs: - name: Test run: | - if [ $REVERSE ]; then - python3 -m pip install pytest-reverse - fi if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then xvfb-run -s '-screen 0 1024x768x24' sway& export WAYLAND_DISPLAY=wayland-1 @@ -135,7 +132,6 @@ jobs: fi env: PYTHONOPTIMIZE: ${{ matrix.PYTHONOPTIMIZE }} - REVERSE: ${{ matrix.REVERSE }} - name: Prepare to upload errors if: failure() From 3d09b1e4a6f648642e17730b14bd3c3a1af13177 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 29 Jun 2025 19:22:26 +0300 Subject: [PATCH 5/7] Run AVIF leak tests in own group to avoid exceeding memory limit locally --- Tests/test_file_avif.py | 1 + pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_avif.py b/Tests/test_file_avif.py index 727191153a1..5ada98bda38 100644 --- a/Tests/test_file_avif.py +++ b/Tests/test_file_avif.py @@ -772,6 +772,7 @@ def test_seek_errors(self) -> None: MAX_THREADS = os.cpu_count() or 1 +@pytest.mark.xdist_group(name="leak-group") @skip_unless_feature("avif") class TestAvifLeaks(PillowLeakTestCase): mem_limit = MAX_THREADS * 3 * 1024 diff --git a/pyproject.toml b/pyproject.toml index db24747523c..2f63f756b57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -209,7 +209,7 @@ lint.isort.required-imports = [ max_supported_python = "3.14" [tool.pytest.ini_options] -addopts = "-ra --color=auto --numprocesses=auto" +addopts = "-ra --color=auto --numprocesses=auto --dist=loadgroup" testpaths = [ "Tests", ] From 6007c59e4571c53fa561de34fa8da03793f8afb0 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 14 Dec 2025 22:52:11 +0200 Subject: [PATCH 6/7] Run imagegrab tests in single group to prevent clashes with external tools --- Tests/test_imagegrab.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index 01fa090dc3a..da272da722f 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -12,6 +12,7 @@ from .helper import assert_image_equal_tofile, skip_unless_feature +@pytest.mark.xdist_group(name="imagegrab-group") class TestImageGrab: @pytest.mark.skipif( os.environ.get("USERNAME") == "ContainerAdministrator", From 48476e068ad7b4c603745b95cb21844d63986f5d Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 23 Dec 2025 18:36:27 +0200 Subject: [PATCH 7/7] Remove make test-p --- Makefile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Makefile b/Makefile index b4456437174..fd106110899 100644 --- a/Makefile +++ b/Makefile @@ -97,12 +97,6 @@ test: python3 -c "import pytest" > /dev/null 2>&1 || python3 -m pip install pytest python3 -m pytest -qq -.PHONY: test-p -test-p: - python3 -c "import xdist" > /dev/null 2>&1 || python3 -m pip install pytest-xdist - python3 -m pytest -qq -n auto - - .PHONY: valgrind valgrind: python3 -c "import pytest_valgrind" > /dev/null 2>&1 || python3 -m pip install pytest-valgrind