Skip to content

Silently eats DistributionNotFound errors #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
matthijskooijman opened this issue Aug 14, 2018 · 7 comments
Open

Silently eats DistributionNotFound errors #174

matthijskooijman opened this issue Aug 14, 2018 · 7 comments

Comments

@matthijskooijman
Copy link

I was running into an issue with pluggy, because it eats DistributionNotFound errors. In my case, this prevented most of my installed pytest plugins from being used, without any indication as to why.

The root cause of the DistributionNotFound error was a missing dependency. I installed pytest from a [Pipfile.lock] that was (presumably) generated on a Unix system, where pytest does not depend on the colorama package. However, I was running on a Windows system, so pytest was installed without all of its dependencies. When pluggy tries to load pytest plugins, which (I presume) depend again on pytest, pkg_resources notices this missing dependency and raises a DistributionNotFound error, which is silently eaten by pluggy.

For reference, here is the traceback that's being eaten (by adding a traceback.print_exc() inside pluggy):

Traceback (most recent call last):
  File "c:\users\brenda\.virtualenvs\django-machina-_lipc3zt\lib\site-packages\pluggy\manager.py", line 254, in load_setuptools_entrypoints
    plugin = ep.load()
  File "c:\users\brenda\.virtualenvs\django-machina-_lipc3zt\lib\site-packages\pkg_resources\__init__.py", line 2320, in load
    self.require(*args, **kwargs)
  File "c:\users\brenda\.virtualenvs\django-machina-_lipc3zt\lib\site-packages\pkg_resources\__init__.py", line 2343, in require
    items = working_set.resolve(reqs, env, installer, extras=self.extras)
  File "c:\users\brenda\.virtualenvs\django-machina-_lipc3zt\lib\site-packages\pkg_resources\__init__.py", line 777, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'colorama; sys_platform == "win32"' distribution was not found and is required by pytest

Why does pluggy eat this error? I traced the history back to the pytest repo and the change was introduced in this commit: pytest-dev/pytest@1bc444d, but that does not really tell me why it was introduced....

@RonnyPfannschmidt
Copy link
Member

@matthijskooijman its absolutely unclear why @hpk42 keept that "diaper" thing in

@nicoddemus
Copy link
Member

It is unclear indeed. I propose that we drop the try/except and let the error propagate; I can't think we would ever want to silently discard plugin errors.

@RonnyPfannschmidt
Copy link
Member

@nicoddemus just letting them bubble without some extra intervention in pytest will be a breaking api change

@nicoddemus
Copy link
Member

nicoddemus commented Aug 19, 2018 via email

@matthijskooijman
Copy link
Author

One problem with catching that error in pytest, is that the exception will have broken the loop, so any entry points that come after the problematic one, will be skipped.

@RonnyPfannschmidt
Copy link
Member

just hit that since pip and setuptools normalize distribution names differently and a requirement that worked fine with pip triggered a hard setuptools failure in not finding the package name since pip finds foo_bar as foo.bar and setuptools doesnt

@khvn26
Copy link

khvn26 commented Feb 15, 2019

Apparently pkg_resources swallows ImportErrors so should plugin code contain import errors, pytest will exit 1 in utter and complete silence. We use our own plugins located in the tested codebase in our CI pipelines and this issue has just caused a long and confusing troubleshooting session since our linter didn't catch the import errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants