Skip to content

Commit 52aadcd

Browse files
committed
Strip whitespace from markers in INI config
Resolves #2856.
1 parent 4cb60da commit 52aadcd

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

_pytest/mark.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ def _check(self, name):
272272
pass
273273
self._markers = l = set()
274274
for line in self._config.getini("markers"):
275-
beginning = line.split(":", 1)
276-
x = beginning[0].split("(", 1)[0]
275+
marker, _ = line.split(":", 1)
276+
marker = marker.rstrip()
277+
x = marker.split("(", 1)[0]
277278
l.add(x)
278279
if name not in self._markers:
279280
raise AttributeError("%r not a registered marker" % (name,))

changelog/2856.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Strip whitespace from marker names when reading them from INI config.

testing/test_mark.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ def test_markers_option(testdir):
169169
])
170170

171171

172+
def test_ini_markers_whitespace(testdir):
173+
testdir.makeini("""
174+
[pytest]
175+
markers =
176+
a1 : this is a whitespace marker
177+
""")
178+
testdir.makepyfile("""
179+
import pytest
180+
181+
@pytest.mark.a1
182+
def test_markers():
183+
assert True
184+
""")
185+
rec = testdir.inline_run("--strict", "-m", "a1")
186+
rec.assertoutcome(passed=1)
187+
188+
172189
def test_markers_option_with_plugin_in_current_dir(testdir):
173190
testdir.makeconftest('pytest_plugins = "flip_flop"')
174191
testdir.makepyfile(flip_flop="""\

0 commit comments

Comments
 (0)