diff --git a/resources/test/fixtures/N802.py b/resources/test/fixtures/N802.py index 7cc1c90191..73fee4e207 100644 --- a/resources/test/fixtures/N802.py +++ b/resources/test/fixtures/N802.py @@ -1,3 +1,6 @@ +import unittest + + def Bad(): pass @@ -24,3 +27,15 @@ def _good(): def good_func(): pass + + +def tearDownModule(): + pass + + +class Test(unittest.TestCase): + def tearDown(self): + return super().tearDown() + + def testTest(self): + assert True diff --git a/src/pep8_naming/checks.rs b/src/pep8_naming/checks.rs index ffdde7e76b..834dfa4ef8 100644 --- a/src/pep8_naming/checks.rs +++ b/src/pep8_naming/checks.rs @@ -21,8 +21,23 @@ pub fn invalid_class_name(class_def: &Stmt, name: &str) -> Option { None } +const IGNORE_NAMES: &[&str] = &[ + "setUp", + "tearDown", + "setUpClass", + "tearDownClass", + "setUpModule", + "tearDownModule", + "asyncSetUp", + "asyncTearDown", + "setUpTestData", + "failureException", + "longMessage", + "maxDiff", +]; + pub fn invalid_function_name(func_def: &Stmt, name: &str) -> Option { - if name.chars().any(|c| c.is_uppercase()) { + if !is_lower(name) && !IGNORE_NAMES.contains(&name) { return Some(Check::new( CheckKind::InvalidFunctionName(name.to_string()), Range::from_located(func_def), @@ -32,7 +47,7 @@ pub fn invalid_function_name(func_def: &Stmt, name: &str) -> Option { } pub fn invalid_argument_name(location: Range, name: &str) -> Option { - if name.chars().any(|c| c.is_uppercase()) { + if !is_lower(name) { return Some(Check::new( CheckKind::InvalidArgumentName(name.to_string()), location, diff --git a/src/snapshots/ruff__linter__tests__N802_N802.py.snap b/src/snapshots/ruff__linter__tests__N802_N802.py.snap index 63da8ffbd5..ff76160b07 100644 --- a/src/snapshots/ruff__linter__tests__N802_N802.py.snap +++ b/src/snapshots/ruff__linter__tests__N802_N802.py.snap @@ -5,37 +5,46 @@ expression: checks - kind: InvalidFunctionName: Bad location: - row: 1 + row: 4 column: 1 end_location: - row: 5 + row: 8 column: 1 fix: ~ - kind: InvalidFunctionName: _Bad location: - row: 5 + row: 8 column: 1 end_location: - row: 9 + row: 12 column: 1 fix: ~ - kind: InvalidFunctionName: BAD location: - row: 9 + row: 12 column: 1 end_location: - row: 13 + row: 16 column: 1 fix: ~ - kind: InvalidFunctionName: BAD_FUNC location: - row: 13 + row: 16 column: 1 end_location: - row: 17 + row: 20 + column: 1 + fix: ~ +- kind: + InvalidFunctionName: testTest + location: + row: 40 + column: 5 + end_location: + row: 42 column: 1 fix: ~