Refactor logging of fixtures
This commit is contained in:
parent
7d19f83982
commit
92bcc36266
|
@ -2460,12 +2460,8 @@ class FixtureDef:
|
||||||
# the cached fixture value
|
# the cached fixture value
|
||||||
if hasattr(self, "cached_result"):
|
if hasattr(self, "cached_result"):
|
||||||
if self._fixturemanager.config.option.setuponly:
|
if self._fixturemanager.config.option.setuponly:
|
||||||
tw = self._fixturemanager.config.get_terminal_writer()
|
self._log_fixture_stack('TEARDOWN')
|
||||||
tw.line()
|
|
||||||
tw.write(' ' * 2 * self.scopenum)
|
|
||||||
tw.write('TEARDOWN {} {}'.format(self.scope[0].upper(), self.argname))
|
|
||||||
if hasattr(self, "cached_param"):
|
if hasattr(self, "cached_param"):
|
||||||
tw.write('[{}]'.format(self.cached_param))
|
|
||||||
del self.cached_param
|
del self.cached_param
|
||||||
del self.cached_result
|
del self.cached_result
|
||||||
|
|
||||||
|
@ -2512,19 +2508,33 @@ class FixtureDef:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = call_fixture_func(fixturefunc, request, kwargs)
|
result = call_fixture_func(fixturefunc, request, kwargs)
|
||||||
tw = request.config.get_terminal_writer()
|
# We want to access the params of ids if they exist also in during
|
||||||
tw.line()
|
# the finish() method.
|
||||||
tw.write(' ' * 2 * self.scopenum)
|
if self._fixturemanager.config.option.setuponly:
|
||||||
tw.write('SETUP {} {}'.format(self.scope[0].upper(), fixturefunc.__name__))
|
|
||||||
if hasattr(request, 'param'):
|
if hasattr(request, 'param'):
|
||||||
tw.write('[{}]'.format(request.param))
|
if self.ids:
|
||||||
|
ind = self.params.index(request.param)
|
||||||
|
self.cached_param = self.ids[ind]
|
||||||
|
else:
|
||||||
self.cached_param = request.param
|
self.cached_param = request.param
|
||||||
|
self._log_fixture_stack('SETUP')
|
||||||
except Exception:
|
except Exception:
|
||||||
self.cached_result = (None, my_cache_key, sys.exc_info())
|
self.cached_result = (None, my_cache_key, sys.exc_info())
|
||||||
raise
|
raise
|
||||||
self.cached_result = (result, my_cache_key, None)
|
self.cached_result = (result, my_cache_key, None)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def _log_fixture_stack(self, what):
|
||||||
|
tw = self._fixturemanager.config.get_terminal_writer()
|
||||||
|
tw.line()
|
||||||
|
tw.write(' ' * 2 * self.scopenum)
|
||||||
|
tw.write('{step} {scope} {fixture}'.format(
|
||||||
|
step=what.ljust(8), # align the output to TEARDOWN
|
||||||
|
scope=self.scope[0].upper(),
|
||||||
|
fixture=self.argname))
|
||||||
|
if hasattr(self, 'cached_param'):
|
||||||
|
tw.write('[{}]'.format(self.cached_param))
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return ("<FixtureDef name=%r scope=%r baseid=%r >" %
|
return ("<FixtureDef name=%r scope=%r baseid=%r >" %
|
||||||
(self.argname, self.scope, self.baseid))
|
(self.argname, self.scope, self.baseid))
|
||||||
|
|
Loading…
Reference in New Issue