Skip to content

Commit 27935eb

Browse files
authored
Merge pull request #2943 from Perlence/fix-marks-without-description
Handle marks without description
2 parents 8df7ed1 + 378eb5d commit 27935eb

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

_pytest/mark.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ def pytest_cmdline_main(config):
119119
config._do_configure()
120120
tw = _pytest.config.create_terminal_writer(config)
121121
for line in config.getini("markers"):
122-
name, rest = line.split(":", 1)
122+
parts = line.split(":", 1)
123+
name = parts[0]
124+
rest = parts[1] if len(parts) == 2 else ''
123125
tw.write("@pytest.mark.%s:" % name, bold=True)
124126
tw.line(rest)
125127
tw.line()
@@ -272,7 +274,7 @@ def _check(self, name):
272274
pass
273275
self._markers = values = set()
274276
for line in self._config.getini("markers"):
275-
marker, _ = line.split(":", 1)
277+
marker = line.split(":", 1)[0]
276278
marker = marker.rstrip()
277279
x = marker.split("(", 1)[0]
278280
values.add(x)

changelog/2942.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle marks without description in ``pytest.ini``.

testing/test_mark.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,13 @@ def test_markers_option(testdir):
161161
markers =
162162
a1: this is a webtest marker
163163
a1some: another marker
164+
nodescription
164165
""")
165166
result = testdir.runpytest("--markers", )
166167
result.stdout.fnmatch_lines([
167168
"*a1*this is a webtest*",
168169
"*a1some*another marker",
170+
"*nodescription*",
169171
])
170172

171173

@@ -186,6 +188,21 @@ def test_markers():
186188
rec.assertoutcome(passed=1)
187189

188190

191+
def test_marker_without_description(testdir):
192+
testdir.makefile(".cfg", setup="""
193+
[tool:pytest]
194+
markers=slow
195+
""")
196+
testdir.makeconftest("""
197+
import pytest
198+
pytest.mark.xfail('FAIL')
199+
""")
200+
ftdir = testdir.mkdir("ft1_dummy")
201+
testdir.tmpdir.join("conftest.py").move(ftdir.join("conftest.py"))
202+
rec = testdir.runpytest_subprocess("--strict")
203+
rec.assert_outcomes()
204+
205+
189206
def test_markers_option_with_plugin_in_current_dir(testdir):
190207
testdir.makeconftest('pytest_plugins = "flip_flop"')
191208
testdir.makepyfile(flip_flop="""\

0 commit comments

Comments
 (0)