Skip to content

Commit 801ce0e

Browse files
jaracoclaude
andcommitted
Restore the stdlib distribution finder after removing importlib_metadata in conftest.
Otherwise, no distributions are discoverable during the test session, and pytest fails to start now that pluggy 1.7 resolves its version through importlib.metadata. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d2485ac commit 801ce0e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎conftest.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,21 @@ def remove_importlib_metadata():
2727
for mod in list(sys.modules):
2828
if mod.startswith('importlib_metadata'):
2929
del sys.modules[mod]
30+
restore_stdlib_finder()
31+
32+
33+
def restore_stdlib_finder():
34+
"""
35+
Restore the stdlib distribution finder.
36+
37+
A previous import of importlib_metadata disables the stdlib
38+
finder (``_compat.disable_stdlib_finder``). With the backport's
39+
finder removed above, no distributions would be discoverable
40+
(breaking ``pluggy.__version__``, for one). Restore the stdlib
41+
behavior until importlib_metadata is imported again.
42+
"""
43+
from importlib.machinery import PathFinder
44+
from importlib.metadata import MetadataPathFinder
45+
46+
if not hasattr(PathFinder, 'find_distributions'):
47+
PathFinder.find_distributions = MetadataPathFinder.find_distributions

0 commit comments

Comments
 (0)