File tree Expand file tree Collapse file tree 5 files changed +36
-8
lines changed Expand file tree Collapse file tree 5 files changed +36
-8
lines changed Original file line number Diff line number Diff line change 1+ Fix ``--setup-only `` and ``--setup-show `` for custom pytest items.
Original file line number Diff line number Diff line change @@ -107,8 +107,8 @@ def show_test_item(item):
107107 tw = item .config .get_terminal_writer ()
108108 tw .line ()
109109 tw .write (" " * 8 )
110- tw .write (item ._nodeid )
111- used_fixtures = sorted (item . _fixtureinfo . name2fixturedefs . keys ( ))
110+ tw .write (item .nodeid )
111+ used_fixtures = sorted (getattr ( item , "fixturenames" , [] ))
112112 if used_fixtures :
113113 tw .write (" (fixtures used: {})" .format (", " .join (used_fixtures )))
114114
Original file line number Diff line number Diff line change @@ -88,3 +88,30 @@ def get_write_msg(self, idx):
8888 fullwidth = 80
8989
9090 return TWMock ()
91+
92+
93+ @pytest .fixture
94+ def dummy_yaml_custom_test (testdir ):
95+ """Writes a conftest file that collects and executes a dummy yaml test.
96+
97+ Taken from the docs, but stripped down to the bare minimum, useful for
98+ tests which needs custom items collected.
99+ """
100+ testdir .makeconftest (
101+ """
102+ import pytest
103+
104+ def pytest_collect_file(parent, path):
105+ if path.ext == ".yaml" and path.basename.startswith("test"):
106+ return YamlFile(path, parent)
107+
108+ class YamlFile(pytest.File):
109+ def collect(self):
110+ yield YamlItem(self.fspath.basename, self)
111+
112+ class YamlItem(pytest.Item):
113+ def runtest(self):
114+ pass
115+ """
116+ )
117+ testdir .makefile (".yaml" , test1 = "" )
Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ def mode(request):
66 return request .param
77
88
9- def test_show_only_active_fixtures (testdir , mode ):
10- p = testdir .makepyfile (
9+ def test_show_only_active_fixtures (testdir , mode , dummy_yaml_custom_test ):
10+ testdir .makepyfile (
1111 '''
1212 import pytest
1313 @pytest.fixture
@@ -21,7 +21,7 @@ def test_arg1(arg1):
2121 '''
2222 )
2323
24- result = testdir .runpytest (mode , p )
24+ result = testdir .runpytest (mode )
2525 assert result .ret == 0
2626
2727 result .stdout .fnmatch_lines (
Original file line number Diff line number Diff line change 1- def test_show_fixtures_and_test (testdir ):
1+ def test_show_fixtures_and_test (testdir , dummy_yaml_custom_test ):
22 """ Verifies that fixtures are not executed. """
3- p = testdir .makepyfile (
3+ testdir .makepyfile (
44 """
55 import pytest
66 @pytest.fixture
@@ -11,7 +11,7 @@ def test_arg(arg):
1111 """
1212 )
1313
14- result = testdir .runpytest ("--setup-plan" , p )
14+ result = testdir .runpytest ("--setup-plan" )
1515 assert result .ret == 0
1616
1717 result .stdout .fnmatch_lines (
You can’t perform that action at this time.
0 commit comments