Skip to content

Commit 443797a

Browse files
authored
Merge pull request #891 from piazzesiNiccolo/unit_test_deprecated_aliases_bug
fix bug when rewriting deprecated unittest functions
2 parents b499613 + c98e8ed commit 443797a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pyupgrade/_plugins/unittest_aliases.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from tokenize_rt import Offset
88

99
from pyupgrade._ast_helpers import ast_to_offset
10+
from pyupgrade._ast_helpers import has_starargs
1011
from pyupgrade._data import register
1112
from pyupgrade._data import State
1213
from pyupgrade._data import TokenFunc
@@ -59,7 +60,10 @@ def visit_Call(
5960
isinstance(node.func, ast.Attribute) and
6061
isinstance(node.func.value, ast.Name) and
6162
node.func.value.id == 'unittest' and
62-
node.func.attr in FUNCTION_MAPPING
63+
node.func.attr in FUNCTION_MAPPING and
64+
not has_starargs(node) and
65+
not node.keywords and
66+
len(node.args) == 1
6367
):
6468
func = functools.partial(
6569
replace_name,

tests/features/unittest_aliases_test.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77

88

99
@pytest.mark.parametrize(
10-
('s',),
10+
's',
1111
(
1212
pytest.param(
1313
'class ExampleTests:\n'
1414
' def test_something(self):\n'
1515
' self.assertEqual(1, 1)\n',
1616
id='not a deprecated alias',
1717
),
18+
'unittest.makeSuite(Tests, "arg")',
19+
'unittest.makeSuite(Tests, prefix="arg")',
1820
),
1921
)
2022
def test_fix_unittest_aliases_noop(s):

0 commit comments

Comments
 (0)