Merge pull request #5886 from nicoddemus/setup-plan-custom-items-5884
Fix --setup-only and --setup-show for custom pytest items
This commit is contained in:
commit
b62276826c
|
@ -0,0 +1 @@
|
|||
Fix ``--setup-only`` and ``--setup-show`` for custom pytest items.
|
|
@ -107,8 +107,8 @@ def show_test_item(item):
|
|||
tw = item.config.get_terminal_writer()
|
||||
tw.line()
|
||||
tw.write(" " * 8)
|
||||
tw.write(item._nodeid)
|
||||
used_fixtures = sorted(item._fixtureinfo.name2fixturedefs.keys())
|
||||
tw.write(item.nodeid)
|
||||
used_fixtures = sorted(getattr(item, "fixturenames", []))
|
||||
if used_fixtures:
|
||||
tw.write(" (fixtures used: {})".format(", ".join(used_fixtures)))
|
||||
|
||||
|
|
|
@ -88,3 +88,30 @@ def tw_mock():
|
|||
fullwidth = 80
|
||||
|
||||
return TWMock()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dummy_yaml_custom_test(testdir):
|
||||
"""Writes a conftest file that collects and executes a dummy yaml test.
|
||||
|
||||
Taken from the docs, but stripped down to the bare minimum, useful for
|
||||
tests which needs custom items collected.
|
||||
"""
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
def pytest_collect_file(parent, path):
|
||||
if path.ext == ".yaml" and path.basename.startswith("test"):
|
||||
return YamlFile(path, parent)
|
||||
|
||||
class YamlFile(pytest.File):
|
||||
def collect(self):
|
||||
yield YamlItem(self.fspath.basename, self)
|
||||
|
||||
class YamlItem(pytest.Item):
|
||||
def runtest(self):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
testdir.makefile(".yaml", test1="")
|
||||
|
|
|
@ -6,8 +6,8 @@ def mode(request):
|
|||
return request.param
|
||||
|
||||
|
||||
def test_show_only_active_fixtures(testdir, mode):
|
||||
p = testdir.makepyfile(
|
||||
def test_show_only_active_fixtures(testdir, mode, dummy_yaml_custom_test):
|
||||
testdir.makepyfile(
|
||||
'''
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
|
@ -21,7 +21,7 @@ def test_show_only_active_fixtures(testdir, mode):
|
|||
'''
|
||||
)
|
||||
|
||||
result = testdir.runpytest(mode, p)
|
||||
result = testdir.runpytest(mode)
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
def test_show_fixtures_and_test(testdir):
|
||||
def test_show_fixtures_and_test(testdir, dummy_yaml_custom_test):
|
||||
""" Verifies that fixtures are not executed. """
|
||||
p = testdir.makepyfile(
|
||||
testdir.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
|
@ -11,7 +11,7 @@ def test_show_fixtures_and_test(testdir):
|
|||
"""
|
||||
)
|
||||
|
||||
result = testdir.runpytest("--setup-plan", p)
|
||||
result = testdir.runpytest("--setup-plan")
|
||||
assert result.ret == 0
|
||||
|
||||
result.stdout.fnmatch_lines(
|
||||
|
|
Loading…
Reference in New Issue