-
Notifications
You must be signed in to change notification settings - Fork 78
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
TurboGears2 and pytest conflict #118
Comments
Given the pretty uncommon chances that a StackedObjectProxy is used as a callable and the even less common chances that it gets decorated, I think that 77132ba is a reasonable work-around to the problem. I hoped that removing |
Yeah, that seems like an OK way to avoid the problem. Thanks.
|
Probably going for all dunder methods makes sense. I'll update the patch. Regarding how to avoid problem with current version. I think that the issue comes from the fact that it's exploring all variables exposed in modules or something like that. Maybe changing |
Work around an issue that has been reported on TurboGears/tg2#118 : .../site-packages/_pytest/doctest.py:381: in _mock_aware_unwrap return real_unwrap(obj, stop=_is_mocked) /usr/lib64/python3.7/inspect.py:511: in unwrap while _is_wrapper(func): /usr/lib64/python3.7/inspect.py:505: in _is_wrapper return hasattr(f, '__wrapped__') and not stop(f) .../site-packages/tg/support/objectproxy.py:19: in __getattr__ return getattr(self._current_obj(), attr) .../site-packages/tg/request_local.py:240: in _current_obj return getattr(context, self.name) .../site-packages/tg/support/objectproxy.py:19: in __getattr__ return getattr(self._current_obj(), attr) .../site-packages/tg/support/registry.py:72: in _current_obj 'thread' % self.____name__) E TypeError: No object (name: context) has been registered for this thread pytest's doctest support is (in _mock_aware_unwrap) using py3 inspect. Inside inspect, _is_wrapper will do an innocent looking: hasattr(f, '__wrapped__') But if the code under test has un (unused) import of a tg context (such as tg.request), it is no longer so innocent. tg will throw: TypeError: No object (name: context) has been registered for this thread (which in py2 would have caught by hasattr, but not in py3.) pytest will thus fail already in the "collecting ..." phase. To work around that, use the hack of pushing a tg context in the top level pytest_configure.
TurboGears2 and pytest doesn't in all cases play well together. Like when using the
from tg import tmpl_context
pattern used in the documentation in combination with pytest for running doctests.pytest's doctest support is (in
_mock_aware_unwrap
) using py3 inspect.Inside inspect,
_is_wrapper
will do an innocent looking:hasattr(f, '__wrapped__')
But if the code under test has un (unused) import of a tg context (such as
tg.request), it is no longer so innocent. tg will throw:
TypeError: No object (name: context) has been registered for this thread
(which in py2 would have caught by hasattr, but not in py3.)
I don't know if it should be solved in pytest (perhaps by not using inspect), in TurboGears (perhaps by having a default context or at least be aware of how the standard library use
__wrapped__
), or in inspect.This might be the core of the 2nd problem mentioned on #117
The text was updated successfully, but these errors were encountered: