Skip to content

Needs to handle VersionConflict in consider_setuptools_entrypoints #704

Closed

Description

@pytestbot

Originally reported by: Daniel Hahler (BitBucket: blueyed, GitHub: blueyed)


I was getting the following error, caused by the testmon plugin, which
requires pytest<2.7:

…/pyenv/project2/lib/python2.7/site-packages/_pytest/config.py in _preparse(self, args, addopts)
    711         self._checkversion()
    712         self.pluginmanager.consider_preparse(args)
--> 713         self.pluginmanager.consider_setuptools_entrypoints()
    714         self.pluginmanager.consider_env()
    715         self.known_args_namespace = ns = self._parser.parse_known_args(args)

…/pyenv/project2/lib/python2.7/site-packages/_pytest/core.py in consider_setuptools_entrypoints(self)
    276                 continue
    277             try:
--> 278                 plugin = ep.load()
    279             except DistributionNotFound:
    280                 continue

…/pyenv/project2/lib/python2.7/site-packages/pkg_resources/__init__.py in load(self, require, *args, **kwargs)
   2318             )
   2319         if require:
-> 2320             self.require(*args, **kwargs)
   2321         return self.resolve()
   2322 

…/pyenv/project2/lib/python2.7/site-packages/pkg_resources/__init__.py in require(self, env, installer)
   2335             raise UnknownExtra("Can't require() without a distribution", self)
   2336         reqs = self.dist.requires(self.extras)
-> 2337         items = working_set.resolve(reqs, env, installer)
   2338         list(map(working_set.add, items))
   2339 

…/pyenv/project2/lib/python2.7/site-packages/pkg_resources/__init__.py in resolve(self, requirements, env, installer, replace_conflicting)
    812                 dependent_req = required_by[req]
    813                 import ipdb; ipdb.set_trace()  # noqa
--> 814                 raise VersionConflict(dist, req).with_context(dependent_req)
    815 
    816             # push the new requirements onto the stack

VersionConflict: (pytest 2.7.0 (…/pyenv/project2/lib/python2.7/site-packages), Requirement.parse('pytest<2.7'))


ipdb> args
self = <pkg_resources.WorkingSet object at 0x7f3ec2a55cd0>
requirements = [Requirement.parse('pathtools>=0.1.1'), Requirement.parse('argh>=0.24.1'), Requirement.parse('PyYAML>=3.10'), Requirement.parse('execnet>=1.1.dev1'), Requ
irement.parse('pytest>=2.2')]                                                                                                                                            env = None
installer = None
replace_conflicting = False

ep is EntryPoint.parse('testmon = testmon.plugin').

It would be nice if there was a warning in such a case and the plugin was
skipped.

A warning might be useful with the current handling of DistributionNotFound,
too.


Activity

  1. RonnyPfannschmidt commented on Jul 25, 2015

    @RonnyPfannschmidt
    Member

    this is now in pluggy, @hpk42 @flub - is this a candidate for a person at the sprint?

  2. flub commented on Jul 25, 2015

    @flub
    Member

    Yes, sure
    On 25 Jul 2015 11:50, "Ronny Pfannschmidt" notifications@github.com wrote:

    this is now in pluggy, @hpk42 https://github.com/hpk42 @flub
    https://github.com/flub - is this a candidate for a person at the
    sprint?

    —
    Reply to this email directly or view it on GitHub
    #704 (comment).

  3. modified the milestones: 2.8, on Sep 13, 2015
  4. nicoddemus commented on Sep 26, 2015

    @nicoddemus
    Member

    Is this still an issue?

  5. removed this from the 2.8.1 milestone on Sep 26, 2015
  6. RonnyPfannschmidt commented on Sep 27, 2015

    @RonnyPfannschmidt
    Member

    I think pluggy has a better handling now, wed need to vendor and test

  7. added a commit that references this issue on Sep 27, 2015
    910b25d
  8. added a commit that references this issue on Sep 28, 2015
    d29084e
  9. blueyed commented on Mar 4, 2016

    @blueyed
    Contributor

    Still not better:

    Traceback (most recent call last):
      File "…/pyenv/project/bin/py.test", line 9, in <module>
        load_entry_point('pytest', 'console_scripts', 'py.test')()
      File "…/pytest/_pytest/config.py", line 39, in main
        config = _prepareconfig(args, plugins)
      File "…/pytest/_pytest/config.py", line 118, in _prepareconfig
        pluginmanager=pluginmanager, args=args)
      File "…/pytest/_pytest/vendored_packages/pluggy.py", line 724, in __call__
        return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
      File "…/pytest/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
        return self._inner_hookexec(hook, methods, kwargs)
      File "…/pytest/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
        _MultiCall(methods, kwargs, hook.spec_opts).execute()
      File "…/pytest/_pytest/vendored_packages/pluggy.py", line 595, in execute
        return _wrapped_call(hook_impl.function(*args), self.execute)
      File "…/pytest/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
        wrap_controller.send(call_outcome)
      File "…/pytest/_pytest/helpconfig.py", line 28, in pytest_cmdline_parse
        config = outcome.get_result()
      File "…/pytest/_pytest/vendored_packages/pluggy.py", line 278, in get_result
        raise ex[1].with_traceback(ex[2])
      File "…/pytest/_pytest/vendored_packages/pluggy.py", line 264, in __init__
        self.result = func()
      File "…/pytest/_pytest/vendored_packages/pluggy.py", line 596, in execute
        res = hook_impl.function(*args)
      File "…/pytest/_pytest/config.py", line 856, in pytest_cmdline_parse
        self.parse(args)
      File "…/pytest/_pytest/config.py", line 961, in parse
        self._preparse(args, addopts=addopts)
      File "…/pytest/_pytest/config.py", line 922, in _preparse
        self.pluginmanager.load_setuptools_entrypoints("pytest11")
      File "…/pytest/_pytest/vendored_packages/pluggy.py", line 501, in load_setuptools_entrypoints
        plugin = ep.load()
      File "…/pyenv/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2379, in load
        self.require(*args, **kwargs)
      File "…/pyenv/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2396, in require
        items = working_set.resolve(reqs, env, installer)
      File "…/pyenv/project/lib/python3.5/site-packages/pkg_resources/__init__.py", line 854, in resolve
        raise VersionConflict(dist, req).with_context(dependent_req)
    pkg_resources.VersionConflict: (pytest 2.9.1.dev1 (…/pytest), Requirement.parse('pytest<2.9,>=2.7.0'))
    

    This happened with an older pytest-testmon package, after only updating pytest.

    Where is the upstream source for pluggy hosted?

    A patch could look like this, but should also display the error / problem (mentioning also ep/ep.name):

    diff --git i/_pytest/vendored_packages/pluggy.py w/_pytest/vendored_packages/pluggy.
    index 2f848b2..3ed558b 100644
    --- i/_pytest/vendored_packages/pluggy.py
    +++ w/_pytest/vendored_packages/pluggy.py
    @@ -492,7 +492,8 @@ def check_pending(self):
         def load_setuptools_entrypoints(self, entrypoint_name):
             """ Load modules from querying the specified setuptools entrypoint name.
             Return the number of loaded plugins. """
    -        from pkg_resources import iter_entry_points, DistributionNotFound
    +        from pkg_resources import (iter_entry_points, DistributionNotFound,
    +                                   VersionConflict)
             for ep in iter_entry_points(entrypoint_name):
                 # is the plugin registered or blocked?
                 if self.get_plugin(ep.name) or self.is_blocked(ep.name):
    @@ -501,6 +502,8 @@ def load_setuptools_entrypoints(self, entrypoint_name):
                     plugin = ep.load()
                 except DistributionNotFound:
                     continue
    +            except VersionConflict as excinfo:
    +                continue
                 self.register(plugin, name=ep.name)
                 self._plugin_distinfo.append((plugin, ep.dist))
             return len(self._plugin_distinfo)
  10. reopened this on Mar 4, 2016
  11. The-Compiler commented on Mar 4, 2016

    @The-Compiler
    Member

    Where is the upstream source for pluggy hosted?

    https://github.com/hpk42/pluggy

  12. blueyed commented on Jun 21, 2016

    @blueyed
    Contributor

    Thanks, it was fixed in pytest-dev/pluggy#8.

  13. blueyed commented on Jun 21, 2016

    @blueyed
    Contributor

    But 0.3.2 is not released and vendored yet.
    Not sure if this issue for pytest should get re-opened.
    A new release of pluggy seems to be a good idea for the (end of the) sprint?! https://github.com/hpk42/pluggy/blob/master/CHANGELOG

  14. nicoddemus commented on Jun 22, 2016

    @nicoddemus
    Member

    That's a good idea @blueyed, created an issue for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions