Skip to content

Commit 499c955

Browse files
committed
Implement working version of --setuponly
1 parent 54872e9 commit 499c955

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

_pytest/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def pytest_addoption(parser):
4848
help="run pytest in strict mode, warnings become errors.")
4949
group._addoption("-c", metavar="file", type=str, dest="inifilename",
5050
help="load configuration from `file` instead of trying to locate one of the implicit configuration files.")
51+
group.addoption('--setuponly', '--setup-only', action="store_true",
52+
help="only setup fixtures, don't execute the tests.")
5153

5254
group = parser.getgroup("collect", "collection")
5355
group.addoption('--collectonly', '--collect-only', action="store_true",

_pytest/python.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,6 +2459,14 @@ def finish(self):
24592459
# even if finalization fails, we invalidate
24602460
# the cached fixture value
24612461
if hasattr(self, "cached_result"):
2462+
if self._fixturemanager.config.option.setuponly:
2463+
tw = self._fixturemanager.config.get_terminal_writer()
2464+
tw.line()
2465+
tw.write(' ' * 2 * self.scopenum)
2466+
tw.write('TEARDOWN {} {}'.format(self.scope[0].upper(), self.argname))
2467+
if hasattr(self, "cached_param"):
2468+
tw.write('[{}]'.format(self.cached_param))
2469+
del self.cached_param
24622470
del self.cached_result
24632471

24642472
def execute(self, request):
@@ -2504,6 +2512,13 @@ def execute(self, request):
25042512

25052513
try:
25062514
result = call_fixture_func(fixturefunc, request, kwargs)
2515+
tw = request.config.get_terminal_writer()
2516+
tw.line()
2517+
tw.write(' ' * 2 * self.scopenum)
2518+
tw.write('SETUP {} {}'.format(self.scope[0].upper(), fixturefunc.__name__))
2519+
if hasattr(request, 'param'):
2520+
tw.write('[{}]'.format(request.param))
2521+
self.cached_param = request.param
25072522
except Exception:
25082523
self.cached_result = (None, my_cache_key, sys.exc_info())
25092524
raise

_pytest/runner.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,17 @@ def runtestprotocol(item, log=True, nextitem=None):
7373
rep = call_and_report(item, "setup", log)
7474
reports = [rep]
7575
if rep.passed:
76-
reports.append(call_and_report(item, "call", log))
76+
if item.config.option.setuponly:
77+
tw = item.config.get_terminal_writer()
78+
tw.line()
79+
tw.write(' ' * 8)
80+
tw.write('{} '.format(item._nodeid))
81+
used_fixtures = sorted(item._fixtureinfo.name2fixturedefs.keys())
82+
if used_fixtures:
83+
tw.write('fixtures: ')
84+
tw.write(', '.join(used_fixtures))
85+
else:
86+
reports.append(call_and_report(item, "call", log))
7787
reports.append(call_and_report(item, "teardown", log,
7888
nextitem=nextitem))
7989
# after all teardown hooks have been called

0 commit comments

Comments
 (0)