Skip to content

Commit de6eb4c

Browse files
committed
add ini option to disable string escape for parametrization
1 parent 9b51fc6 commit de6eb4c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

_pytest/python.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def pytest_addoption(parser):
8181
parser.addini("python_functions", type="args", default=["test",],
8282
help="prefixes or glob names for Python test function and "
8383
"method discovery")
84+
parser.addini("disable_test_id_escaping_and_forfeit_all_rights_to_community_support", type="bool",
85+
default=False, help="disable string escape non-ascii"
86+
" characters, might cause unwanted side effects")
8487

8588
group.addoption("--import-mode", default="prepend",
8689
choices=["prepend", "append"], dest="importmode",
@@ -909,7 +912,11 @@ def _idval(val, argname, idx, idfn, config=None):
909912
return hook_id
910913

911914
if isinstance(val, STRING_TYPES):
912-
return _escape_strings(val)
915+
if config is None:
916+
escape_option = False
917+
else:
918+
escape_option = config.getini("disable_test_id_escaping_and_forfeit_all_rights_to_community_support")
919+
return val if escape_option else _escape_strings(val)
913920
elif isinstance(val, (float, int, bool, NoneType)):
914921
return str(val)
915922
elif isinstance(val, REGEX_TYPE):

doc/en/parametrize.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ them in turn::
7878
test_expectation.py:8: AssertionError
7979
======= 1 failed, 2 passed in 0.12 seconds ========
8080

81+
82+
.. note::
83+
84+
pytest by default escapes any non-ascii characters used in unicode strings
85+
for the parametrization because it has several downsides.
86+
If however you would like to use them, use the option disable_test_id_escaping_and_forfeit_all_rights_to_community_support = False
87+
to disable this behavior, but keep in mind that this might cause unwanted side effects and
88+
even bugs depending on the OS used and plugins currently installed, so use it at your own risk.
89+
90+
8191
As designed in this example, only one pair of input/output values fails
8292
the simple test function. And as usual with test function arguments,
8393
you can see the ``input`` and ``output`` values in the traceback.

0 commit comments

Comments
 (0)