Implement working version of --setuponly

This commit is contained in:
Steffen Allner 2016-06-21 18:28:40 +02:00
parent 54872e94b4
commit 499c9551c8
3 changed files with 28 additions and 1 deletions

View File

@ -48,6 +48,8 @@ def pytest_addoption(parser):
help="run pytest in strict mode, warnings become errors.")
group._addoption("-c", metavar="file", type=str, dest="inifilename",
help="load configuration from `file` instead of trying to locate one of the implicit configuration files.")
group.addoption('--setuponly', '--setup-only', action="store_true",
help="only setup fixtures, don't execute the tests.")
group = parser.getgroup("collect", "collection")
group.addoption('--collectonly', '--collect-only', action="store_true",

View File

@ -2459,6 +2459,14 @@ class FixtureDef:
# even if finalization fails, we invalidate
# the cached fixture value
if hasattr(self, "cached_result"):
if self._fixturemanager.config.option.setuponly:
tw = self._fixturemanager.config.get_terminal_writer()
tw.line()
tw.write(' ' * 2 * self.scopenum)
tw.write('TEARDOWN {} {}'.format(self.scope[0].upper(), self.argname))
if hasattr(self, "cached_param"):
tw.write('[{}]'.format(self.cached_param))
del self.cached_param
del self.cached_result
def execute(self, request):
@ -2504,6 +2512,13 @@ class FixtureDef:
try:
result = call_fixture_func(fixturefunc, request, kwargs)
tw = request.config.get_terminal_writer()
tw.line()
tw.write(' ' * 2 * self.scopenum)
tw.write('SETUP {} {}'.format(self.scope[0].upper(), fixturefunc.__name__))
if hasattr(request, 'param'):
tw.write('[{}]'.format(request.param))
self.cached_param = request.param
except Exception:
self.cached_result = (None, my_cache_key, sys.exc_info())
raise

View File

@ -73,7 +73,17 @@ def runtestprotocol(item, log=True, nextitem=None):
rep = call_and_report(item, "setup", log)
reports = [rep]
if rep.passed:
reports.append(call_and_report(item, "call", log))
if item.config.option.setuponly:
tw = item.config.get_terminal_writer()
tw.line()
tw.write(' ' * 8)
tw.write('{} '.format(item._nodeid))
used_fixtures = sorted(item._fixtureinfo.name2fixturedefs.keys())
if used_fixtures:
tw.write('fixtures: ')
tw.write(', '.join(used_fixtures))
else:
reports.append(call_and_report(item, "call", log))
reports.append(call_and_report(item, "teardown", log,
nextitem=nextitem))
# after all teardown hooks have been called