Skip to content

Commit

Permalink
Merge pull request #891 from piazzesiNiccolo/unit_test_deprecated_ali…
Browse files Browse the repository at this point in the history
…ases_bug

fix bug when rewriting deprecated unittest functions
  • Loading branch information
asottile committed Sep 21, 2023
2 parents b499613 + c98e8ed commit 443797a
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 443797a

Please sign in to comment.