From c98e8ed362a3972b5a2a3065afdebcfbb62a9a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Piazzesi?= Date: Thu, 21 Sep 2023 17:04:16 +0200 Subject: [PATCH] prevent rewriting unittest module functions with additional arguments --- pyupgrade/_plugins/unittest_aliases.py | 6 +++++- tests/features/unittest_aliases_test.py | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pyupgrade/_plugins/unittest_aliases.py b/pyupgrade/_plugins/unittest_aliases.py index 6ab643b9..4b1a745d 100644 --- a/pyupgrade/_plugins/unittest_aliases.py +++ b/pyupgrade/_plugins/unittest_aliases.py @@ -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 @@ -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, diff --git a/tests/features/unittest_aliases_test.py b/tests/features/unittest_aliases_test.py index cc3124e9..041ad736 100644 --- a/tests/features/unittest_aliases_test.py +++ b/tests/features/unittest_aliases_test.py @@ -7,7 +7,7 @@ @pytest.mark.parametrize( - ('s',), + 's', ( pytest.param( 'class ExampleTests:\n' @@ -15,6 +15,8 @@ ' 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):