File tree Expand file tree Collapse file tree 6 files changed +57
-3
lines changed Expand file tree Collapse file tree 6 files changed +57
-3
lines changed Original file line number Diff line number Diff line change @@ -408,6 +408,7 @@ Sviatoslav Sydorenko
408
408
Sylvain Marié
409
409
Tadek Teleżyński
410
410
Takafumi Arakaki
411
+ Takumi Otani
411
412
Taneli Hukkinen
412
413
Tanvi Mehta
413
414
Tanya Agarwal
Original file line number Diff line number Diff line change
1
+ Honor :confval: `disable_test_id_escaping_and_forfeit_all_rights_to_community_support ` when escaping ids in parametrized tests.
Original file line number Diff line number Diff line change @@ -1332,6 +1332,29 @@ passed multiple times. The expected format is ``name=value``. For example::
1332
1332
console_output_style = classic
1333
1333
1334
1334
1335
+ .. confval :: disable_test_id_escaping_and_forfeit_all_rights_to_community_support
1336
+
1337
+ .. versionadded :: 4.4
1338
+
1339
+ pytest by default escapes any non-ascii characters used in unicode strings
1340
+ for the parametrization because it has several downsides.
1341
+ If however you would like to use unicode strings in parametrization
1342
+ and see them in the terminal as is (non-escaped), use this option
1343
+ in your ``pytest.ini ``:
1344
+
1345
+ .. code-block :: ini
1346
+
1347
+ [pytest]
1348
+ disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True
1349
+
1350
+ Keep in mind however that this might cause unwanted side effects and
1351
+ even bugs depending on the OS used and plugins currently installed,
1352
+ so use it at your own risk.
1353
+
1354
+ Default: ``False ``.
1355
+
1356
+ See :ref: `parametrizemark `.
1357
+
1335
1358
.. confval :: doctest_encoding
1336
1359
1337
1360
Original file line number Diff line number Diff line change 21
21
import warnings
22
22
23
23
from .._code import getfslineno
24
- from ..compat import ascii_escaped
25
24
from ..compat import NOTSET
26
25
from ..compat import NotSetType
27
26
from _pytest .config import Config
@@ -97,7 +96,6 @@ def param(
97
96
if id is not None :
98
97
if not isinstance (id , str ):
99
98
raise TypeError (f"Expected id to be a string, got { type (id )} : { id !r} " )
100
- id = ascii_escaped (id )
101
99
return cls (values , marks , id )
102
100
103
101
@classmethod
Original file line number Diff line number Diff line change @@ -924,7 +924,7 @@ def _resolve_ids(self) -> Iterable[str]:
924
924
for idx , parameterset in enumerate (self .parametersets ):
925
925
if parameterset .id is not None :
926
926
# ID provided directly - pytest.param(..., id="...")
927
- yield parameterset .id
927
+ yield _ascii_escaped_by_config ( parameterset .id , self . config )
928
928
elif self .ids and idx < len (self .ids ) and self .ids [idx ] is not None :
929
929
# ID provided in the IDs list - parametrize(..., ids=[...]).
930
930
yield self ._idval_from_value_required (self .ids [idx ], idx )
Original file line number Diff line number Diff line change @@ -625,6 +625,37 @@ def getini(self, name):
625
625
).make_unique_parameterset_ids ()
626
626
assert result == [expected ]
627
627
628
+ def test_idmaker_with_param_id_and_config (self ) -> None :
629
+ """Unit test for expected behavior to create ids with pytest.param(id=...) and
630
+ disable_test_id_escaping_and_forfeit_all_rights_to_community_support
631
+ option (#9037).
632
+ """
633
+
634
+ class MockConfig :
635
+ def __init__ (self , config ):
636
+ self .config = config
637
+
638
+ def getini (self , name ):
639
+ return self .config [name ]
640
+
641
+ option = "disable_test_id_escaping_and_forfeit_all_rights_to_community_support"
642
+
643
+ values : list [tuple [Any , str ]] = [
644
+ (MockConfig ({option : True }), "ação" ),
645
+ (MockConfig ({option : False }), "a\\ xe7\\ xe3o" ),
646
+ ]
647
+ for config , expected in values :
648
+ result = IdMaker (
649
+ ("a" ,),
650
+ [pytest .param ("string" , id = "ação" )],
651
+ None ,
652
+ None ,
653
+ config ,
654
+ None ,
655
+ None ,
656
+ ).make_unique_parameterset_ids ()
657
+ assert result == [expected ]
658
+
628
659
def test_idmaker_duplicated_empty_str (self ) -> None :
629
660
"""Regression test for empty strings parametrized more than once (#11563)."""
630
661
result = IdMaker (
You can’t perform that action at this time.
0 commit comments