Implement --setup-plan option
This commit is contained in:
parent
5e0d78f4f1
commit
61992b4e22
|
@ -50,6 +50,9 @@ def pytest_addoption(parser):
|
|||
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.addoption('--setupplan', '--setup-plan', action="store_true",
|
||||
help="show what fixtures and tests would be executed but don't"
|
||||
" execute anything.")
|
||||
|
||||
group = parser.getgroup("collect", "collection")
|
||||
group.addoption('--collectonly', '--collect-only', action="store_true",
|
||||
|
|
|
@ -2459,7 +2459,8 @@ class FixtureDef:
|
|||
# even if finalization fails, we invalidate
|
||||
# the cached fixture value
|
||||
if hasattr(self, "cached_result"):
|
||||
if self._fixturemanager.config.option.setuponly:
|
||||
config = self._fixturemanager.config
|
||||
if config.option.setuponly or config.option.setupplan:
|
||||
self._log_fixture_stack('TEARDOWN')
|
||||
if hasattr(self, "cached_param"):
|
||||
del self.cached_param
|
||||
|
@ -2507,10 +2508,14 @@ class FixtureDef:
|
|||
fixturefunc = fixturefunc.__get__(request.instance)
|
||||
|
||||
try:
|
||||
config = request.config
|
||||
if config.option.setupplan:
|
||||
result = None
|
||||
else:
|
||||
result = call_fixture_func(fixturefunc, request, kwargs)
|
||||
if config.option.setuponly or config.option.setupplan:
|
||||
# We want to access the params of ids if they exist also in during
|
||||
# the finish() method.
|
||||
if self._fixturemanager.config.option.setuponly:
|
||||
if hasattr(request, 'param'):
|
||||
if self.ids:
|
||||
ind = self.params.index(request.param)
|
||||
|
|
|
@ -73,7 +73,7 @@ def runtestprotocol(item, log=True, nextitem=None):
|
|||
rep = call_and_report(item, "setup", log)
|
||||
reports = [rep]
|
||||
if rep.passed:
|
||||
if item.config.option.setuponly:
|
||||
if item.config.option.setuponly or item.config.option.setupplan:
|
||||
show_test_item(item)
|
||||
else:
|
||||
reports.append(call_and_report(item, "call", log))
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
def test_show_only_active_fixtures(testdir):
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(params=['--setup-only', '--setup-plan'], scope='module')
|
||||
def mode(request):
|
||||
return request.param
|
||||
|
||||
|
||||
def test_show_only_active_fixtures(testdir, mode):
|
||||
p = testdir.makepyfile('''
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
|
@ -11,7 +19,7 @@ def test_show_only_active_fixtures(testdir):
|
|||
pass
|
||||
''')
|
||||
|
||||
result = testdir.runpytest("--setup-only", p)
|
||||
result = testdir.runpytest(mode, p)
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines([
|
||||
|
@ -22,7 +30,7 @@ def test_show_only_active_fixtures(testdir):
|
|||
assert "_arg0" not in result.stdout.str()
|
||||
|
||||
|
||||
def test_show_different_scopes(testdir):
|
||||
def test_show_different_scopes(testdir, mode):
|
||||
p = testdir.makepyfile('''
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
|
@ -35,7 +43,7 @@ def test_show_different_scopes(testdir):
|
|||
pass
|
||||
''')
|
||||
|
||||
result = testdir.runpytest("--setup-only", p)
|
||||
result = testdir.runpytest(mode, p)
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines([
|
||||
|
@ -47,7 +55,7 @@ def test_show_different_scopes(testdir):
|
|||
])
|
||||
|
||||
|
||||
def test_show_nested_fixtures(testdir):
|
||||
def test_show_nested_fixtures(testdir, mode):
|
||||
testdir.makeconftest('''
|
||||
import pytest
|
||||
@pytest.fixture(scope='session')
|
||||
|
@ -63,7 +71,7 @@ def test_show_nested_fixtures(testdir):
|
|||
pass
|
||||
''')
|
||||
|
||||
result = testdir.runpytest("--setup-only", p)
|
||||
result = testdir.runpytest(mode, p)
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines([
|
||||
|
@ -75,7 +83,7 @@ def test_show_nested_fixtures(testdir):
|
|||
])
|
||||
|
||||
|
||||
def test_show_fixtures_with_autouse(testdir):
|
||||
def test_show_fixtures_with_autouse(testdir, mode):
|
||||
p = testdir.makepyfile('''
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
|
@ -88,7 +96,7 @@ def test_show_fixtures_with_autouse(testdir):
|
|||
pass
|
||||
''')
|
||||
|
||||
result = testdir.runpytest("--setup-only", p)
|
||||
result = testdir.runpytest(mode, p)
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines([
|
||||
|
@ -98,7 +106,7 @@ def test_show_fixtures_with_autouse(testdir):
|
|||
])
|
||||
|
||||
|
||||
def test_show_fixtures_with_parameters(testdir):
|
||||
def test_show_fixtures_with_parameters(testdir, mode):
|
||||
testdir.makeconftest('''
|
||||
import pytest
|
||||
@pytest.fixture(scope='session', params=['foo', 'bar'])
|
||||
|
@ -114,7 +122,7 @@ def test_show_fixtures_with_parameters(testdir):
|
|||
pass
|
||||
''')
|
||||
|
||||
result = testdir.runpytest("--setup-only", p)
|
||||
result = testdir.runpytest(mode, p)
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines([
|
||||
|
@ -125,7 +133,7 @@ def test_show_fixtures_with_parameters(testdir):
|
|||
])
|
||||
|
||||
|
||||
def test_show_fixtures_with_parameter_ids(testdir):
|
||||
def test_show_fixtures_with_parameter_ids(testdir, mode):
|
||||
testdir.makeconftest('''
|
||||
import pytest
|
||||
@pytest.fixture(
|
||||
|
@ -142,7 +150,7 @@ def test_show_fixtures_with_parameter_ids(testdir):
|
|||
pass
|
||||
''')
|
||||
|
||||
result = testdir.runpytest("--setup-only", p)
|
||||
result = testdir.runpytest(mode, p)
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines([
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
def test_show_fixtures_and_test(testdir):
|
||||
p = testdir.makepyfile('''
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
def arg():
|
||||
assert False
|
||||
def test_arg(arg):
|
||||
assert False
|
||||
''')
|
||||
|
||||
result = testdir.runpytest("--setup-plan", p)
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines([
|
||||
'*SETUP F arg*',
|
||||
'*test_arg (fixtures used: arg)',
|
||||
'*TEARDOWN F arg*',
|
||||
])
|
Loading…
Reference in New Issue