Skip to content

Commit f794723

Browse files
committed
Remove importlib_metadata as imported by pytest. Fixes #322.
1 parent ea72278 commit f794723

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

conftest.py

+21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1+
import sys
2+
3+
14
collect_ignore = [
25
# this module fails mypy tests because 'setup.py' matches './setup.py'
36
'prepare/example/setup.py',
47
]
8+
9+
10+
def pytest_configure():
11+
remove_importlib_metadata()
12+
13+
14+
def remove_importlib_metadata():
15+
"""
16+
Because pytest imports importlib_metadata, the coverage
17+
reports are broken (#322). So work around the issue by
18+
undoing the changes made by pytest's import of
19+
importlib_metadata (if any).
20+
"""
21+
if sys.meta_path[-1].__class__.__name__ == 'MetadataPathFinder':
22+
del sys.meta_path[-1]
23+
for mod in list(sys.modules):
24+
if mod.startswith('importlib_metadata'):
25+
del sys.modules[mod]

0 commit comments

Comments
 (0)