Skip to content
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

Crash with special objects in plugins #1073

Closed
pelme opened this issue Sep 26, 2015 · 3 comments
Closed

Crash with special objects in plugins #1073

pelme opened this issue Sep 26, 2015 · 3 comments
Labels
type: bug problem that needs to be addressed
Milestone

Comments

@pelme
Copy link
Member

pelme commented Sep 26, 2015

Having objects in conftest that cannot have getattr called causes pytest to crash.

Here is a small example that shows this:

conftest.py:

class DontTouchMe:
    def __getattr__(self, x):
        raise Exception('cant touch me')

x = DontTouchMe()
$ py.test
Traceback (most recent call last):
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/bin/py.test", line 11, in <module>
    sys.exit(main())
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 38, in main
    config = _prepareconfig(args, plugins)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 117, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/helpconfig.py", line 28, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
    _reraise(*ex)  # noqa
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
    self.result = func()
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
    res = hook_impl.function(*args)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 851, in pytest_cmdline_parse
    self.parse(args)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 956, in parse
    self._preparse(args)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 927, in _preparse
    args=args, parser=self._parser)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 253, in _wrapped_call
    return call_outcome.get_result()
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
    _reraise(*ex)  # noqa
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
    self.result = func()
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
    res = hook_impl.function(*args)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 897, in pytest_load_initial_conftests
    self.pluginmanager._set_initial_conftests(early_config.known_args_namespace)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 267, in _set_initial_conftests
    self._try_load_conftest(current)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 270, in _try_load_conftest
    self._getconftestmodules(anchor)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 295, in _getconftestmodules
    mod = self._importconftest(conftestpath)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 331, in _importconftest
    self.consider_conftest(mod)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 354, in consider_conftest
    if self.register(conftestmodule, name=conftestmodule.__file__):
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 206, in register
    ret = super(PytestPluginManager, self).register(plugin, name)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 359, in register
    hookimpl_opts = self.parse_hookimpl_opts(plugin, name)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/config.py", line 178, in parse_hookimpl_opts
    opts = super(PytestPluginManager, self).parse_hookimpl_opts(plugin, name)
  File "/Users/andreas/.virtualenvs/tempenv-303f27199658c/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 377, in parse_hookimpl_opts
    res = getattr(method, self.project_name + "_impl", None)
  File "/Users/andreas/slask/kaka/conftest.py", line 3, in __getattr__
    raise Exception('cant touch me')
Exception: cant touch me

This happens in practice with django settings (django.conf.settings) that must not be touched until Django is properly configured: pytest-dev/pytest-django#272

pelme added a commit to pytest-dev/pytest-django that referenced this issue Sep 26, 2015
@nicoddemus nicoddemus added this to the 2.8.1 milestone Sep 26, 2015
@nicoddemus nicoddemus added the type: bug problem that needs to be addressed label Sep 26, 2015
@pelme
Copy link
Member Author

pelme commented Sep 27, 2015

Is this a bug in pluggy?

@RonnyPfannschmidt
Copy link
Member

@pelme yes, the workflow for fixing is fixing in pluggy, doing a pluggy release and then vendoring that pluggy release into pytest

@nicoddemus
Copy link
Member

Created a PR at pytest-dev/pluggy#12. As @RonnyPfannschmidt said, oOnce that is merged and a new pluggy is released, we must vendor it back into pytest before closing this.

hpk42 added a commit to hpk42/pytest that referenced this issue Sep 28, 2015
@hpk42 hpk42 closed this as completed in 03aca9e Sep 28, 2015
RonnyPfannschmidt added a commit that referenced this issue Sep 28, 2015
fix issue #1073 -- shortcut plugin hook lookup if the attrname is not prefixed with pytest_.
tomviner pushed a commit to tomviner/pytest-django that referenced this issue Jun 22, 2016
mfa pushed a commit to aexeagmbh/pytest-django that referenced this issue May 17, 2017
beyondgeeks added a commit to beyondgeeks/django-pytest that referenced this issue Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

3 participants