Implement working version of --setuponly
This commit is contained in:
parent
54872e94b4
commit
499c9551c8
|
@ -48,6 +48,8 @@ def pytest_addoption(parser):
|
||||||
help="run pytest in strict mode, warnings become errors.")
|
help="run pytest in strict mode, warnings become errors.")
|
||||||
group._addoption("-c", metavar="file", type=str, dest="inifilename",
|
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.")
|
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 = parser.getgroup("collect", "collection")
|
||||||
group.addoption('--collectonly', '--collect-only', action="store_true",
|
group.addoption('--collectonly', '--collect-only', action="store_true",
|
||||||
|
|
|
@ -2459,6 +2459,14 @@ class FixtureDef:
|
||||||
# even if finalization fails, we invalidate
|
# even if finalization fails, we invalidate
|
||||||
# the cached fixture value
|
# the cached fixture value
|
||||||
if hasattr(self, "cached_result"):
|
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
|
del self.cached_result
|
||||||
|
|
||||||
def execute(self, request):
|
def execute(self, request):
|
||||||
|
@ -2504,6 +2512,13 @@ class FixtureDef:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = call_fixture_func(fixturefunc, request, kwargs)
|
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:
|
except Exception:
|
||||||
self.cached_result = (None, my_cache_key, sys.exc_info())
|
self.cached_result = (None, my_cache_key, sys.exc_info())
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -73,7 +73,17 @@ def runtestprotocol(item, log=True, nextitem=None):
|
||||||
rep = call_and_report(item, "setup", log)
|
rep = call_and_report(item, "setup", log)
|
||||||
reports = [rep]
|
reports = [rep]
|
||||||
if rep.passed:
|
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,
|
reports.append(call_and_report(item, "teardown", log,
|
||||||
nextitem=nextitem))
|
nextitem=nextitem))
|
||||||
# after all teardown hooks have been called
|
# after all teardown hooks have been called
|
||||||
|
|
Loading…
Reference in New Issue