Skip to content

test.test_importlib.resources.test_resource: AttributeError in from . import util #151560

@ringobanana-3900

Description

@ringobanana-3900

Bug report

Bug description:

Currently, I'm having an issue: test_importlib.resources.test_resource is failing at the line from . import util.

Investigating the failure revealed it because importlib.abc isn't imported, which make the interpreter unable to find importlib.abc.MetaPathFinder (and also importlib.abc.Loader).

import abc
import contextlib
import functools
import importlib
import io
import pathlib
import sys
import types
from importlib.machinery import ModuleSpec
from importlib.resources.abc import ResourceReader, Traversable, TraversableResources
from test.support import import_helper, os_helper
from . import _path
from . import zip as zip_

class MemoryFinder(importlib.abc.MetaPathFinder):

class MemoryLoader(importlib.abc.Loader):

output of minimal, reproducible example ./python.exe -m test test_importlib.resources.test_resource:

== CPython 3.16.0a0 (heads/main-dirty:5ea1e907d1, Jun 17 2026, 06:10:50) [Clang 22.1.7 ]
== macOS-26.5.1-arm64-arm-64bit-Mach-O little-endian
== Python build: release
== cwd: /Users/ringobanana/cpython/build/test_python_worker_87642æ
== CPU count: 8
== encodings: locale=UTF-8 FS=utf-8
== resources: all test resources are disabled, use -u option to unskip tests

Using random seed: 3583600852
0:00:00 load avg: 3.25 mem: 29.1 MiB Run 1 test in parallel using 1 worker process
0:00:00 load avg: 3.25 mem: 29.1 MiB [1/1/1] test_importlib.resources.test_resource failed (uncaught exception)
test test_importlib.resources.test_resource crashed -- Traceback (most recent call last):
  File "/Users/ringobanana/cpython/Lib/test/libregrtest/single.py", line 210, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/Users/ringobanana/cpython/Lib/test/libregrtest/single.py", line 155, in _load_run_test
    test_mod = importlib.import_module(module_name)
  File "/Users/ringobanana/cpython/Lib/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1375, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1340, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1299, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 909, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 747, in exec_module
  File "<frozen importlib._bootstrap>", line 543, in _call_with_frames_removed
  File "/Users/ringobanana/cpython/Lib/test/test_importlib/resources/test_resource.py", line 6, in <module>
    from . import util
  File "/Users/ringobanana/cpython/Lib/test/test_importlib/resources/util.py", line 206, in <module>
    class MemorySetup(ModuleSetup):
    ...<99 lines>...
                return pathlib.PurePosixPath(self._fullname).name
  File "/Users/ringobanana/cpython/Lib/test/test_importlib/resources/util.py", line 222, in MemorySetup
    class MemoryFinder(importlib.abc.MetaPathFinder):
                       ^^^^^^^^^^^^^
AttributeError: module 'importlib' has no attribute 'abc'. Did you mean '.resources.abc' instead of '.abc'?

== Tests result: FAILURE ==

1 test failed:
    test_importlib.resources.test_resource

Total duration: 208 ms
Total tests: run=0
Total test files: run=1/1 failed=1
Result: FAILURE

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtopic-importlibtype-bugAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions