diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index f1892aa3f..14a684745 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -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 diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 605814e65..ef6993d94 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -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