19
19
from _pytest .outcomes import fail
20
20
from _pytest .pytester import Testdir
21
21
from _pytest .python import _idval
22
+ from _pytest .python import idmaker
22
23
23
24
24
25
class TestMetafunc :
@@ -35,10 +36,11 @@ def __init__(self, names):
35
36
@attr .s
36
37
class DefinitionMock (python .FunctionDefinition ):
37
38
obj = attr .ib ()
39
+ _nodeid = attr .ib ()
38
40
39
41
names = fixtures .getfuncargnames (func )
40
42
fixtureinfo = FuncFixtureInfoMock (names ) # type: Any
41
- definition = DefinitionMock ._create (func ) # type: Any
43
+ definition = DefinitionMock ._create (func , "mock::nodeid" ) # type: Any
42
44
return python .Metafunc (definition , fixtureinfo , config )
43
45
44
46
def test_no_funcargs (self ) -> None :
@@ -270,7 +272,7 @@ class A:
270
272
deadline = 400.0
271
273
) # very close to std deadline and CI boxes are not reliable in CPU power
272
274
def test_idval_hypothesis (self , value ) -> None :
273
- escaped = _idval (value , "a" , 6 , None , item = None , config = None )
275
+ escaped = _idval (value , "a" , 6 , None , nodeid = None , config = None )
274
276
assert isinstance (escaped , str )
275
277
escaped .encode ("ascii" )
276
278
@@ -292,7 +294,7 @@ def test_unicode_idval(self) -> None:
292
294
),
293
295
]
294
296
for val , expected in values :
295
- assert _idval (val , "a" , 6 , None , item = None , config = None ) == expected
297
+ assert _idval (val , "a" , 6 , None , nodeid = None , config = None ) == expected
296
298
297
299
def test_unicode_idval_with_config (self ) -> None :
298
300
"""unittest for expected behavior to obtain ids with
@@ -321,7 +323,7 @@ def getini(self, name):
321
323
("ação" , MockConfig ({option : False }), "a\\ xe7\\ xe3o" ),
322
324
] # type: List[Tuple[str, Any, str]]
323
325
for val , config , expected in values :
324
- actual = _idval (val , "a" , 6 , None , item = None , config = config )
326
+ actual = _idval (val , "a" , 6 , None , nodeid = None , config = config )
325
327
assert actual == expected
326
328
327
329
def test_bytes_idval (self ) -> None :
@@ -338,7 +340,7 @@ def test_bytes_idval(self) -> None:
338
340
("αρά" .encode (), "\\ xce\\ xb1\\ xcf\\ x81\\ xce\\ xac" ),
339
341
]
340
342
for val , expected in values :
341
- assert _idval (val , "a" , 6 , idfn = None , item = None , config = None ) == expected
343
+ assert _idval (val , "a" , 6 , idfn = None , nodeid = None , config = None ) == expected
342
344
343
345
def test_class_or_function_idval (self ) -> None :
344
346
"""unittest for the expected behavior to obtain ids for parametrized
@@ -353,12 +355,10 @@ def test_function():
353
355
354
356
values = [(TestClass , "TestClass" ), (test_function , "test_function" )]
355
357
for val , expected in values :
356
- assert _idval (val , "a" , 6 , None , item = None , config = None ) == expected
358
+ assert _idval (val , "a" , 6 , None , nodeid = None , config = None ) == expected
357
359
358
360
def test_idmaker_autoname (self ) -> None :
359
361
"""#250"""
360
- from _pytest .python import idmaker
361
-
362
362
result = idmaker (
363
363
("a" , "b" ), [pytest .param ("string" , 1.0 ), pytest .param ("st-ring" , 2.0 )]
364
364
)
@@ -373,14 +373,10 @@ def test_idmaker_autoname(self) -> None:
373
373
assert result == ["a0-\\ xc3\\ xb4" ]
374
374
375
375
def test_idmaker_with_bytes_regex (self ) -> None :
376
- from _pytest .python import idmaker
377
-
378
376
result = idmaker (("a" ), [pytest .param (re .compile (b"foo" ), 1.0 )])
379
377
assert result == ["foo" ]
380
378
381
379
def test_idmaker_native_strings (self ) -> None :
382
- from _pytest .python import idmaker
383
-
384
380
result = idmaker (
385
381
("a" , "b" ),
386
382
[
@@ -414,8 +410,6 @@ def test_idmaker_native_strings(self) -> None:
414
410
]
415
411
416
412
def test_idmaker_non_printable_characters (self ) -> None :
417
- from _pytest .python import idmaker
418
-
419
413
result = idmaker (
420
414
("s" , "n" ),
421
415
[
@@ -430,8 +424,6 @@ def test_idmaker_non_printable_characters(self) -> None:
430
424
assert result == ["\\ x00-1" , "\\ x05-2" , "\\ x00-3" , "\\ x05-4" , "\\ t-5" , "\\ t-6" ]
431
425
432
426
def test_idmaker_manual_ids_must_be_printable (self ) -> None :
433
- from _pytest .python import idmaker
434
-
435
427
result = idmaker (
436
428
("s" ,),
437
429
[
@@ -442,16 +434,13 @@ def test_idmaker_manual_ids_must_be_printable(self) -> None:
442
434
assert result == ["hello \\ x00" , "hello \\ x05" ]
443
435
444
436
def test_idmaker_enum (self ) -> None :
445
- from _pytest .python import idmaker
446
-
447
437
enum = pytest .importorskip ("enum" )
448
438
e = enum .Enum ("Foo" , "one, two" )
449
439
result = idmaker (("a" , "b" ), [pytest .param (e .one , e .two )])
450
440
assert result == ["Foo.one-Foo.two" ]
451
441
452
442
def test_idmaker_idfn (self ) -> None :
453
443
"""#351"""
454
- from _pytest .python import idmaker
455
444
456
445
def ids (val : object ) -> Optional [str ]:
457
446
if isinstance (val , Exception ):
@@ -471,7 +460,6 @@ def ids(val: object) -> Optional[str]:
471
460
472
461
def test_idmaker_idfn_unique_names (self ) -> None :
473
462
"""#351"""
474
- from _pytest .python import idmaker
475
463
476
464
def ids (val : object ) -> str :
477
465
return "a"
@@ -492,7 +480,6 @@ def test_idmaker_with_idfn_and_config(self) -> None:
492
480
disable_test_id_escaping_and_forfeit_all_rights_to_community_support
493
481
option. (#5294)
494
482
"""
495
- from _pytest .python import idmaker
496
483
497
484
class MockConfig :
498
485
def __init__ (self , config ):
@@ -525,7 +512,6 @@ def test_idmaker_with_ids_and_config(self) -> None:
525
512
disable_test_id_escaping_and_forfeit_all_rights_to_community_support
526
513
option. (#5294)
527
514
"""
528
- from _pytest .python import idmaker
529
515
530
516
class MockConfig :
531
517
def __init__ (self , config ):
@@ -607,16 +593,12 @@ def test_int(arg):
607
593
)
608
594
609
595
def test_idmaker_with_ids (self ) -> None :
610
- from _pytest .python import idmaker
611
-
612
596
result = idmaker (
613
597
("a" , "b" ), [pytest .param (1 , 2 ), pytest .param (3 , 4 )], ids = ["a" , None ]
614
598
)
615
599
assert result == ["a" , "3-4" ]
616
600
617
601
def test_idmaker_with_paramset_id (self ) -> None :
618
- from _pytest .python import idmaker
619
-
620
602
result = idmaker (
621
603
("a" , "b" ),
622
604
[pytest .param (1 , 2 , id = "me" ), pytest .param (3 , 4 , id = "you" )],
@@ -625,8 +607,6 @@ def test_idmaker_with_paramset_id(self) -> None:
625
607
assert result == ["me" , "you" ]
626
608
627
609
def test_idmaker_with_ids_unique_names (self ) -> None :
628
- from _pytest .python import idmaker
629
-
630
610
result = idmaker (
631
611
("a" ), map (pytest .param , [1 , 2 , 3 , 4 , 5 ]), ids = ["a" , "a" , "b" , "c" , "b" ]
632
612
)
0 commit comments