Skip to content

Commit 7f96573

Browse files
committed
Add new github action to test lazy imports all against stdlib.
1 parent a900234 commit 7f96573

2 files changed

Lines changed: 119 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Lazy imports all
2+
3+
# Run the standard library test suite with global lazy imports forced on
4+
# (``PYTHON_LAZY_IMPORTS=all``, equivalent to ``-X lazy_imports=all``).
5+
#
6+
# Modules that are known to fail under lazy imports are listed in
7+
# Lib/test/lazy_imports_all_exclude.txt and skipped here. Remove entries from
8+
# that file as the modules are fixed so this workflow starts guarding them
9+
# against regressions.
10+
11+
on:
12+
workflow_dispatch:
13+
push:
14+
branches: &branches
15+
- 'main'
16+
- '3.*'
17+
paths-ignore: &paths-ignore
18+
- 'Doc/**'
19+
- 'Misc/**'
20+
- '**/*.md'
21+
- '**/*.rst'
22+
pull_request:
23+
branches: *branches
24+
paths-ignore: *paths-ignore
25+
26+
permissions:
27+
contents: read
28+
29+
concurrency:
30+
group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }}
31+
cancel-in-progress: true
32+
33+
env:
34+
FORCE_COLOR: 1
35+
36+
jobs:
37+
lazy-imports:
38+
name: Stdlib tests (lazy imports all)
39+
runs-on: ubuntu-24.04
40+
timeout-minutes: 60
41+
env:
42+
PYTHON_LAZY_IMPORTS: all
43+
EXCLUDE_FILE: Lib/test/lazy_imports_all_exclude.txt
44+
steps:
45+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
46+
with:
47+
persist-credentials: false
48+
- name: Register gcc problem matcher
49+
run: echo "::add-matcher::.github/problem-matchers/gcc.json"
50+
- name: Install dependencies
51+
run: sudo ./.github/workflows/posix-deps-apt.sh
52+
- name: Configure CPython
53+
run: ./configure --config-cache --with-pydebug
54+
- name: Build CPython
55+
run: make -j4
56+
- name: Display build info
57+
run: make pythoninfo
58+
- name: Verify lazy imports are fullly enabled
59+
run: ./python -c "import sys; assert sys.flags.lazy_imports == 1, sys.flags.lazy_imports; print('lazy imports all enabled')"
60+
- name: Build test list (all tests minus the known-failing exclusions)
61+
run: |
62+
set -euo pipefail
63+
./python -m test --list-tests > all_tests.txt
64+
# Strip comments/blank lines from the exclusion file, then drop those
65+
# exact test names (whole-line, fixed-string match) from the run list.
66+
grep -vE '^\s*(#.*)?$' "$EXCLUDE_FILE" > exclude_tests.txt
67+
grep -vxF -f exclude_tests.txt all_tests.txt > run_tests.txt
68+
# Fail loudly if any exclusion entry matched nothing: a stale or
69+
# mistyped name (or a change in `--list-tests` output) would otherwise
70+
# silently stop excluding a module and let it fail the run.
71+
stale=$(comm -23 <(sort -u exclude_tests.txt) <(sort -u all_tests.txt))
72+
if [ -n "$stale" ]; then
73+
echo "::error::Stale entries in $EXCLUDE_FILE (no longer match 'python -m test --list-tests'); remove or fix them:"
74+
echo "$stale"
75+
exit 1
76+
fi
77+
echo "Excluding $(wc -l < exclude_tests.txt) module(s); running $(wc -l < run_tests.txt) of $(wc -l < all_tests.txt)."
78+
- name: Run stdlib tests with lazy imports
79+
run: xvfb-run xargs ./python -m test --fast-ci --timeout=900 < run_tests.txt
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Standard library test modules that currently FAIL under global lazy imports
2+
# (``-X lazy_imports=all`` / ``PYTHON_LAZY_IMPORTS=all``).
3+
#
4+
# The "Lazy Imports All" CI workflow (.github/workflows/lazy-imports-all.yml) runs the
5+
# whole test suite with lazy_imports=all, skipping every module listed
6+
# here. Exclusion is whole-module: a listed module is skipped entirely, so any
7+
# passing tests it contains are not covered until its line is removed. As each
8+
# module is fixed, delete its line so the workflow starts guarding it against
9+
# regressions.
10+
#
11+
# Format: one test name per line, exactly as printed by
12+
# ``python -m test --list-tests``. Lines starting with ``#`` and blank lines
13+
# are ignored. Note that split test packages use a dotted path
14+
# (e.g. test.test_future_stmt.test_future) while ordinary modules use the bare
15+
# name (e.g. test_builtin).
16+
17+
test.test_inspect.test_inspect
18+
test.test_pydoc.test_pydoc
19+
test___all__
20+
test__interpreters
21+
test_builtin
22+
test_clinic
23+
test_compileall
24+
test_crossinterp
25+
test_datetime
26+
test_generated_cases
27+
test_idle
28+
test_import
29+
test_importlib
30+
test_interpreters
31+
test_json
32+
test_lazy_import
33+
test_subprocess
34+
test_symtable
35+
test_tools
36+
test_trace
37+
test_typing
38+
test_unittest
39+
test_xmlrpc
40+
test_zipfile

0 commit comments

Comments
 (0)