Skip to content

Commit

Permalink
Remove MetadataPathFinder regardless of its position.
Browse files Browse the repository at this point in the history
Closes #500
  • Loading branch information
jaraco committed Aug 19, 2024
1 parent 5ddd122 commit 6d9b766
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ def pytest_configure():

def remove_importlib_metadata():
"""
Because pytest imports importlib_metadata, the coverage
reports are broken (#322). So work around the issue by
undoing the changes made by pytest's import of
importlib_metadata (if any).
Ensure importlib_metadata is not imported yet.
Because pytest or other modules might import
importlib_metadata, the coverage reports are broken (#322).
Work around the issue by undoing the changes made by a
previous import of importlib_metadata (if any).
"""
if sys.meta_path[-1].__class__.__name__ == 'MetadataPathFinder':
del sys.meta_path[-1]
sys.meta_path[:] = [
item
for item in sys.meta_path
if item.__class__.__name__ != 'MetadataPathFinder'
]
for mod in list(sys.modules):
if mod.startswith('importlib_metadata'):
del sys.modules[mod]

0 comments on commit 6d9b766

Please sign in to comment.