py3: work around incompatibility between pytest, py3 inspect, and tg...
py3: work around incompatibility between pytest, py3 inspect, and tg
Work around an issue that has been reported on
https://github.com/TurboGears/tg2/issues/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.