Skip to content

Commit

Permalink
Backport of #5389: fix for 'files' = None in broken metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas authored and nicoddemus committed Jun 5, 2019
1 parent 937f945 commit 0ae2771
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/5389.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix regressions of `#5063 <https://github.com/pytest-dev/pytest/pull/5063>`__ for ``importlib_metadata.PathDistribution`` which have their ``files`` attribute being ``None``.
2 changes: 1 addition & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def _mark_plugins_for_rewrite(self, hook):
str(file)
for dist in importlib_metadata.distributions()
if any(ep.group == "pytest11" for ep in dist.entry_points)
for file in dist.files
for file in dist.files or []
)

for name in _iter_rewritable_modules(package_files):
Expand Down
23 changes: 23 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,29 @@ def distributions():
testdir.parseconfig()


def test_importlib_metadata_broken_distribution(testdir, monkeypatch):
"""Integration test for broken distributions with 'files' metadata being None (#5389)"""
monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False)

class DummyEntryPoint:
name = "mytestplugin"
group = "pytest11"

def load(self):
return object()

class Distribution:
version = "1.0"
files = None
entry_points = (DummyEntryPoint(),)

def distributions():
return (Distribution(),)

monkeypatch.setattr(importlib_metadata, "distributions", distributions)
testdir.parseconfig()


@pytest.mark.parametrize("block_it", [True, False])
def test_plugin_preparse_prevents_setuptools_loading(testdir, monkeypatch, block_it):
monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False)
Expand Down

0 comments on commit 0ae2771

Please sign in to comment.