diff --git a/_pytest/main.py b/_pytest/main.py index 47b6cb694..ce0bb4918 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -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", diff --git a/_pytest/python.py b/_pytest/python.py index 526f4be09..244a4ce50 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -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 diff --git a/_pytest/runner.py b/_pytest/runner.py index 4cc2ef6ac..1f7100977 100644 --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -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