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):
107
107
tw = item .config .get_terminal_writer ()
108
108
tw .line ()
109
109
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" , [] ))
112
112
if used_fixtures :
113
113
tw .write (" (fixtures used: {})" .format (", " .join (used_fixtures )))
114
114
Original file line number Diff line number Diff line change @@ -88,3 +88,30 @@ def get_write_msg(self, idx):
88
88
fullwidth = 80
89
89
90
90
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):
6
6
return request .param
7
7
8
8
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 (
11
11
'''
12
12
import pytest
13
13
@pytest.fixture
@@ -21,7 +21,7 @@ def test_arg1(arg1):
21
21
'''
22
22
)
23
23
24
- result = testdir .runpytest (mode , p )
24
+ result = testdir .runpytest (mode )
25
25
assert result .ret == 0
26
26
27
27
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 ):
2
2
""" Verifies that fixtures are not executed. """
3
- p = testdir .makepyfile (
3
+ testdir .makepyfile (
4
4
"""
5
5
import pytest
6
6
@pytest.fixture
@@ -11,7 +11,7 @@ def test_arg(arg):
11
11
"""
12
12
)
13
13
14
- result = testdir .runpytest ("--setup-plan" , p )
14
+ result = testdir .runpytest ("--setup-plan" )
15
15
assert result .ret == 0
16
16
17
17
result .stdout .fnmatch_lines (
You can’t perform that action at this time.
0 commit comments