Skip to content

gh-149640: Add new GitHub action to test lazy_imports=all against test suite #2

gh-149640: Add new GitHub action to test lazy_imports=all against test suite

gh-149640: Add new GitHub action to test lazy_imports=all against test suite #2

name: Tests
# 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
# 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: Lazy imports all enabled
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