Skip to content

Commit 79ef048

Browse files
authored
Merge pull request #5389 from dirk-thomas/patch-1
fix logic if importlib_metadata.PathDistribution.files is None [breaks pytest 4.6.0|1|2]
2 parents 76d5080 + 883db6a commit 79ef048

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

changelog/5389.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix regressions of `#5063 <https://github.com/pytest-dev/pytest/pull/5063>`__ for ``importlib_metadata.PathDistribution`` which have their ``files`` attribute being ``None``.

src/_pytest/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ def _mark_plugins_for_rewrite(self, hook):
784784
str(file)
785785
for dist in importlib_metadata.distributions()
786786
if any(ep.group == "pytest11" for ep in dist.entry_points)
787-
for file in dist.files
787+
for file in dist.files or []
788788
)
789789

790790
for name in _iter_rewritable_modules(package_files):

testing/test_config.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,29 @@ def distributions():
578578
testdir.parseconfig()
579579

580580

581+
def test_importlib_metadata_broken_distribution(testdir, monkeypatch):
582+
"""Integration test for broken distributions with 'files' metadata being None (#5389)"""
583+
monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False)
584+
585+
class DummyEntryPoint:
586+
name = "mytestplugin"
587+
group = "pytest11"
588+
589+
def load(self):
590+
return object()
591+
592+
class Distribution:
593+
version = "1.0"
594+
files = None
595+
entry_points = (DummyEntryPoint(),)
596+
597+
def distributions():
598+
return (Distribution(),)
599+
600+
monkeypatch.setattr(importlib_metadata, "distributions", distributions)
601+
testdir.parseconfig()
602+
603+
581604
@pytest.mark.parametrize("block_it", [True, False])
582605
def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch, block_it):
583606
monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False)

0 commit comments

Comments
 (0)