From 7f9657304ea03b049bacded33713c12db0549e40 Mon Sep 17 00:00:00 2001 From: Brittany Reynoso Date: Mon, 8 Jun 2026 08:19:15 -0700 Subject: [PATCH 1/6] Add new github action to test lazy imports all against stdlib. --- .github/workflows/lazy-imports-all.yml | 79 ++++++++++++++++++++++++++ Lib/test/lazy_imports_all_exclude.txt | 40 +++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 .github/workflows/lazy-imports-all.yml create mode 100644 Lib/test/lazy_imports_all_exclude.txt diff --git a/.github/workflows/lazy-imports-all.yml b/.github/workflows/lazy-imports-all.yml new file mode 100644 index 00000000000000..9cbce26e92b544 --- /dev/null +++ b/.github/workflows/lazy-imports-all.yml @@ -0,0 +1,79 @@ +name: Lazy imports all + +# Run the standard library test suite with global lazy imports forced on +# (``PYTHON_LAZY_IMPORTS=all``, equivalent to ``-X lazy_imports=all``). +# +# Modules that are known to fail under lazy imports are listed in +# Lib/test/lazy_imports_all_exclude.txt and skipped here. Remove entries from +# that file as the modules are fixed so this workflow starts guarding them +# against regressions. + +on: + workflow_dispatch: + push: + branches: &branches + - 'main' + - '3.*' + paths-ignore: &paths-ignore + - 'Doc/**' + - 'Misc/**' + - '**/*.md' + - '**/*.rst' + pull_request: + branches: *branches + paths-ignore: *paths-ignore + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +env: + FORCE_COLOR: 1 + +jobs: + lazy-imports: + name: Stdlib tests (lazy imports all) + runs-on: ubuntu-24.04 + timeout-minutes: 60 + env: + PYTHON_LAZY_IMPORTS: all + EXCLUDE_FILE: Lib/test/lazy_imports_all_exclude.txt + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + - name: Register gcc problem matcher + run: echo "::add-matcher::.github/problem-matchers/gcc.json" + - name: Install dependencies + run: sudo ./.github/workflows/posix-deps-apt.sh + - name: Configure CPython + run: ./configure --config-cache --with-pydebug + - name: Build CPython + run: make -j4 + - name: Display build info + run: make pythoninfo + - name: Verify lazy imports are fullly enabled + run: ./python -c "import sys; assert sys.flags.lazy_imports == 1, sys.flags.lazy_imports; print('lazy imports all enabled')" + - name: Build test list (all tests minus the known-failing exclusions) + run: | + set -euo pipefail + ./python -m test --list-tests > all_tests.txt + # Strip comments/blank lines from the exclusion file, then drop those + # exact test names (whole-line, fixed-string match) from the run list. + grep -vE '^\s*(#.*)?$' "$EXCLUDE_FILE" > exclude_tests.txt + grep -vxF -f exclude_tests.txt all_tests.txt > run_tests.txt + # Fail loudly if any exclusion entry matched nothing: a stale or + # mistyped name (or a change in `--list-tests` output) would otherwise + # silently stop excluding a module and let it fail the run. + stale=$(comm -23 <(sort -u exclude_tests.txt) <(sort -u all_tests.txt)) + if [ -n "$stale" ]; then + echo "::error::Stale entries in $EXCLUDE_FILE (no longer match 'python -m test --list-tests'); remove or fix them:" + echo "$stale" + exit 1 + fi + echo "Excluding $(wc -l < exclude_tests.txt) module(s); running $(wc -l < run_tests.txt) of $(wc -l < all_tests.txt)." + - name: Run stdlib tests with lazy imports + run: xvfb-run xargs ./python -m test --fast-ci --timeout=900 < run_tests.txt diff --git a/Lib/test/lazy_imports_all_exclude.txt b/Lib/test/lazy_imports_all_exclude.txt new file mode 100644 index 00000000000000..ec9df3e12301e9 --- /dev/null +++ b/Lib/test/lazy_imports_all_exclude.txt @@ -0,0 +1,40 @@ +# Standard library test modules that currently FAIL under global lazy imports +# (``-X lazy_imports=all`` / ``PYTHON_LAZY_IMPORTS=all``). +# +# The "Lazy Imports All" CI workflow (.github/workflows/lazy-imports-all.yml) runs the +# whole test suite with lazy_imports=all, skipping every module listed +# here. Exclusion is whole-module: a listed module is skipped entirely, so any +# passing tests it contains are not covered until its line is removed. As each +# module is fixed, delete its line so the workflow starts guarding it against +# regressions. +# +# Format: one test name per line, exactly as printed by +# ``python -m test --list-tests``. Lines starting with ``#`` and blank lines +# are ignored. Note that split test packages use a dotted path +# (e.g. test.test_future_stmt.test_future) while ordinary modules use the bare +# name (e.g. test_builtin). + +test.test_inspect.test_inspect +test.test_pydoc.test_pydoc +test___all__ +test__interpreters +test_builtin +test_clinic +test_compileall +test_crossinterp +test_datetime +test_generated_cases +test_idle +test_import +test_importlib +test_interpreters +test_json +test_lazy_import +test_subprocess +test_symtable +test_tools +test_trace +test_typing +test_unittest +test_xmlrpc +test_zipfile From e8d7aed901ebda9760ab67043d1d0e2561924599 Mon Sep 17 00:00:00 2001 From: Brittany Reynoso Date: Mon, 8 Jun 2026 10:14:41 -0700 Subject: [PATCH 2/6] Adjust GH Action naming to better match existing checks --- .github/workflows/lazy-imports-all.yml | 6 +++--- Lib/test/lazy_imports_all_exclude.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lazy-imports-all.yml b/.github/workflows/lazy-imports-all.yml index 9cbce26e92b544..00707fffd0bfaa 100644 --- a/.github/workflows/lazy-imports-all.yml +++ b/.github/workflows/lazy-imports-all.yml @@ -1,6 +1,6 @@ -name: Lazy imports all +name: Tests (Lazy Imports) -# Run the standard library test suite with global lazy imports forced on +# Run the CPython test suite with global lazy imports forced on # (``PYTHON_LAZY_IMPORTS=all``, equivalent to ``-X lazy_imports=all``). # # Modules that are known to fail under lazy imports are listed in @@ -35,7 +35,7 @@ env: jobs: lazy-imports: - name: Stdlib tests (lazy imports all) + name: lazy_imports=all enabled runs-on: ubuntu-24.04 timeout-minutes: 60 env: diff --git a/Lib/test/lazy_imports_all_exclude.txt b/Lib/test/lazy_imports_all_exclude.txt index ec9df3e12301e9..6c40dd4910a7d0 100644 --- a/Lib/test/lazy_imports_all_exclude.txt +++ b/Lib/test/lazy_imports_all_exclude.txt @@ -1,4 +1,4 @@ -# Standard library test modules that currently FAIL under global lazy imports +# Test modules that currently FAIL under global lazy imports # (``-X lazy_imports=all`` / ``PYTHON_LAZY_IMPORTS=all``). # # The "Lazy Imports All" CI workflow (.github/workflows/lazy-imports-all.yml) runs the From ac21520a537cc26c0d92909629a81394cebd8487 Mon Sep 17 00:00:00 2001 From: Brittany Reynoso Date: Mon, 8 Jun 2026 13:55:33 -0700 Subject: [PATCH 3/6] Address comments for reusability --- .github/workflows/build.yml | 7 +++++++ ....yml => rusable-test-lazy-imports-all.yml} | 20 ++++--------------- 2 files changed, 11 insertions(+), 16 deletions(-) rename .github/workflows/{lazy-imports-all.yml => rusable-test-lazy-imports-all.yml} (89%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 47ea859c5fefbb..11978215c653c8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -496,6 +496,12 @@ jobs: name: hypothesis-example-db path: ${{ env.CPYTHON_BUILDDIR }}/.hypothesis/examples/ + test-lazy-imports-all: + name: 'Test Lazy Imports Fully Enabled' + needs: build-context + if: fromJSON(needs.build-context.outputs.run-tests) + uses: ./.github/workflows/reusable-lazy-imports-all.yml + build-asan: name: 'Address sanitizer' runs-on: ${{ matrix.os }} @@ -669,6 +675,7 @@ jobs: - build-emscripten - build-wasi - test-hypothesis + - test-lazy-imports-all - build-asan - build-san - cross-build-linux diff --git a/.github/workflows/lazy-imports-all.yml b/.github/workflows/rusable-test-lazy-imports-all.yml similarity index 89% rename from .github/workflows/lazy-imports-all.yml rename to .github/workflows/rusable-test-lazy-imports-all.yml index 00707fffd0bfaa..ec9de12a2a9211 100644 --- a/.github/workflows/lazy-imports-all.yml +++ b/.github/workflows/rusable-test-lazy-imports-all.yml @@ -1,4 +1,4 @@ -name: Tests (Lazy Imports) +name: Reusable Lazy Imports Tests # Run the CPython test suite with global lazy imports forced on # (``PYTHON_LAZY_IMPORTS=all``, equivalent to ``-X lazy_imports=all``). @@ -9,19 +9,7 @@ name: Tests (Lazy Imports) # against regressions. on: - workflow_dispatch: - push: - branches: &branches - - 'main' - - '3.*' - paths-ignore: &paths-ignore - - 'Doc/**' - - 'Misc/**' - - '**/*.md' - - '**/*.rst' - pull_request: - branches: *branches - paths-ignore: *paths-ignore + workflow_call: permissions: contents: read @@ -34,8 +22,8 @@ env: FORCE_COLOR: 1 jobs: - lazy-imports: - name: lazy_imports=all enabled + test-lazy-imports-all: + name: 'Test Lazy Imports Fully Enabled' runs-on: ubuntu-24.04 timeout-minutes: 60 env: From 4dab14b359ce30bffbea06c34069e96f96bff32e Mon Sep 17 00:00:00 2001 From: Brittany Reynoso Date: Mon, 8 Jun 2026 13:58:38 -0700 Subject: [PATCH 4/6] Fix double typo + add flaky module --- .github/workflows/build.yml | 2 +- ...-lazy-imports-all.yml => reusable-test-lazy-imports-all.yml} | 0 Lib/test/lazy_imports_all_exclude.txt | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) rename .github/workflows/{rusable-test-lazy-imports-all.yml => reusable-test-lazy-imports-all.yml} (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11978215c653c8..fc1f84dbd17849 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -500,7 +500,7 @@ jobs: name: 'Test Lazy Imports Fully Enabled' needs: build-context if: fromJSON(needs.build-context.outputs.run-tests) - uses: ./.github/workflows/reusable-lazy-imports-all.yml + uses: ./.github/workflows/reusable-test-lazy-imports-all.yml build-asan: name: 'Address sanitizer' diff --git a/.github/workflows/rusable-test-lazy-imports-all.yml b/.github/workflows/reusable-test-lazy-imports-all.yml similarity index 100% rename from .github/workflows/rusable-test-lazy-imports-all.yml rename to .github/workflows/reusable-test-lazy-imports-all.yml diff --git a/Lib/test/lazy_imports_all_exclude.txt b/Lib/test/lazy_imports_all_exclude.txt index 6c40dd4910a7d0..b2c9fc865d271a 100644 --- a/Lib/test/lazy_imports_all_exclude.txt +++ b/Lib/test/lazy_imports_all_exclude.txt @@ -23,6 +23,7 @@ test_clinic test_compileall test_crossinterp test_datetime +test_external_inspection test_generated_cases test_idle test_import From 4900ef0673fbaf2195d7ac74411787ce807fb785 Mon Sep 17 00:00:00 2001 From: Brittany Reynoso Date: Tue, 9 Jun 2026 12:03:41 -0700 Subject: [PATCH 5/6] Update test name --- .github/workflows/build.yml | 2 +- .github/workflows/reusable-test-lazy-imports-all.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fc1f84dbd17849..b1f2c673a80a55 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -497,7 +497,7 @@ jobs: path: ${{ env.CPYTHON_BUILDDIR }}/.hypothesis/examples/ test-lazy-imports-all: - name: 'Test Lazy Imports Fully Enabled' + name: 'Lazy Imports All Enabled' needs: build-context if: fromJSON(needs.build-context.outputs.run-tests) uses: ./.github/workflows/reusable-test-lazy-imports-all.yml diff --git a/.github/workflows/reusable-test-lazy-imports-all.yml b/.github/workflows/reusable-test-lazy-imports-all.yml index ec9de12a2a9211..ad7bf1bf31820a 100644 --- a/.github/workflows/reusable-test-lazy-imports-all.yml +++ b/.github/workflows/reusable-test-lazy-imports-all.yml @@ -23,7 +23,7 @@ env: jobs: test-lazy-imports-all: - name: 'Test Lazy Imports Fully Enabled' + name: 'Lazy Imports All Enabled' runs-on: ubuntu-24.04 timeout-minutes: 60 env: From 41aec251e02dc4715b26c4809e9487fb33a1db8c Mon Sep 17 00:00:00 2001 From: Brittany Reynoso Date: Tue, 9 Jun 2026 14:42:17 -0700 Subject: [PATCH 6/6] Remove concurrency configeration for reusable-test-lazy-imports-all.yml --- .github/workflows/reusable-test-lazy-imports-all.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/reusable-test-lazy-imports-all.yml b/.github/workflows/reusable-test-lazy-imports-all.yml index ad7bf1bf31820a..ed018be8d6ff25 100644 --- a/.github/workflows/reusable-test-lazy-imports-all.yml +++ b/.github/workflows/reusable-test-lazy-imports-all.yml @@ -14,10 +14,6 @@ on: permissions: contents: read -concurrency: - group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - env: FORCE_COLOR: 1