Ensure printable manually-specified param(id=...)

This commit is contained in:
Anthony Sottile 2018-11-18 14:39:17 -08:00
parent 8395b9e25d
commit 9ca0ab6e2b
2 changed files with 14 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import attr
import six
from six.moves import map
from ..compat import ascii_escaped
from ..compat import getfslineno
from ..compat import MappingMixin
from ..compat import NOTSET
@ -77,6 +78,7 @@ class ParameterSet(namedtuple("ParameterSet", "values, marks, id")):
raise TypeError(
"Expected id to be a string, got {}: {!r}".format(type(id_), id_)
)
id_ = ascii_escaped(id_)
return cls(values, marks, id_)
@classmethod

View File

@ -394,6 +394,18 @@ class TestMetafunc(object):
)
assert result == ["\\x00-1", "\\x05-2", "\\x00-3", "\\x05-4"]
def test_idmaker_manual_ids_must_be_printable(self):
from _pytest.python import idmaker
result = idmaker(
("s",),
[
pytest.param("x00", id="hello \x00"),
pytest.param("x05", id="hello \x05"),
],
)
assert result == ["hello \\x00", "hello \\x05"]
def test_idmaker_enum(self):
from _pytest.python import idmaker