@@ -202,6 +202,10 @@ def RaisesRegexOp(context, designator, exceptionClass, expected_regex,
202
202
else :
203
203
return Node (syms .suite , [with_stmt ])
204
204
205
+ def FailOp (indent , kws , arglist , node ):
206
+ new = node .clone ()
207
+ new .set_child (0 , Name ('pytest' ))
208
+ return new
205
209
206
210
def add_import (import_name , node ):
207
211
suite = get_parent_of_type (node , syms .suite )
@@ -292,6 +296,8 @@ def get_import_nodes(node):
292
296
'assertRaisesRegex' : partial (RaisesRegexOp , 'pytest.raises' , 'excinfo' ),
293
297
'assertWarnsRegex' : partial (RaisesRegexOp , 'pytest.warns' , 'record' ),
294
298
299
+ 'fail' : FailOp ,
300
+
295
301
#'assertLogs': -- not to be handled here, is an context handler only
296
302
}
297
303
@@ -378,7 +384,7 @@ class FixSelfAssert(BaseFix):
378
384
PATTERN = """
379
385
power< 'self'
380
386
trailer< '.' method=( %s ) >
381
- trailer< '(' arglist=any ')' >
387
+ trailer< '(' [ arglist=any] ')' >
382
388
>
383
389
""" % ' | ' .join (map (repr ,
384
390
(set (_method_map .keys ()) | set (_method_aliases .keys ()))))
@@ -424,8 +430,10 @@ def process_arg(arg):
424
430
posargs = []
425
431
kwargs = {}
426
432
427
- # This is either a "arglist" or a single argument
428
- if results ['arglist' ].type == syms .arglist :
433
+ # This is either empty, an "arglist", or a single argument
434
+ if 'arglist' not in results :
435
+ pass
436
+ elif results ['arglist' ].type == syms .arglist :
429
437
for arg in results ['arglist' ].children :
430
438
process_arg (arg )
431
439
else :
@@ -439,17 +447,17 @@ def process_arg(arg):
439
447
440
448
required_args , argsdict = utils .resolve_func_args (test_func , posargs , kwargs )
441
449
442
- if method .startswith (('assertRaises' , 'assertWarns' )):
450
+ if method .startswith (('assertRaises' , 'assertWarns' )) or method == 'fail' :
443
451
n_stmt = _method_map [method ](* required_args ,
444
452
indent = find_indentation (node ),
445
453
kws = argsdict ,
446
- arglist = results [ 'arglist' ] ,
454
+ arglist = results . get ( 'arglist' ) ,
447
455
node = node )
448
456
else :
449
457
n_stmt = Node (syms .assert_stmt ,
450
458
[Name ('assert' ),
451
459
_method_map [method ](* required_args , kws = argsdict )])
452
- if argsdict .get ('msg' , None ) is not None :
460
+ if argsdict .get ('msg' , None ) is not None and method != 'fail' :
453
461
n_stmt .children .extend ((Name (',' ), argsdict ['msg' ]))
454
462
455
463
def fix_line_wrapping (x ):
@@ -465,7 +473,7 @@ def fix_line_wrapping(x):
465
473
n_stmt .prefix = node .prefix
466
474
467
475
# add necessary imports
468
- if 'Raises' in method or 'Warns' in method :
476
+ if 'Raises' in method or 'Warns' in method or method == 'fail' :
469
477
add_import ('pytest' , node )
470
478
if ('Regex' in method and not 'Raises' in method and
471
479
not 'Warns' in method ):
0 commit comments