Skip to content

Commit

Permalink
prevent rewriting unittest module functions with additional arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
piazzesiNiccolo committed Sep 21, 2023
1 parent b499613 commit c98e8ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pyupgrade/_plugins/unittest_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from tokenize_rt import Offset

from pyupgrade._ast_helpers import ast_to_offset
from pyupgrade._ast_helpers import has_starargs
from pyupgrade._data import register
from pyupgrade._data import State
from pyupgrade._data import TokenFunc
Expand Down Expand Up @@ -59,7 +60,10 @@ def visit_Call(
isinstance(node.func, ast.Attribute) and
isinstance(node.func.value, ast.Name) and
node.func.value.id == 'unittest' and
node.func.attr in FUNCTION_MAPPING
node.func.attr in FUNCTION_MAPPING and
not has_starargs(node) and
not node.keywords and
len(node.args) == 1
):
func = functools.partial(
replace_name,
Expand Down
4 changes: 3 additions & 1 deletion tests/features/unittest_aliases_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@


@pytest.mark.parametrize(
('s',),
's',
(
pytest.param(
'class ExampleTests:\n'
' def test_something(self):\n'
' self.assertEqual(1, 1)\n',
id='not a deprecated alias',
),
'unittest.makeSuite(Tests, "arg")',
'unittest.makeSuite(Tests, prefix="arg")',
),
)
def test_fix_unittest_aliases_noop(s):
Expand Down

0 comments on commit c98e8ed

Please sign in to comment.