diff --git a/oida/checkers/services.py b/oida/checkers/services.py index 3031c0c..48133a3 100644 --- a/oida/checkers/services.py +++ b/oida/checkers/services.py @@ -60,8 +60,15 @@ def _check_if_service_or_selector(self) -> bool: if self.name in ("services", "selectors"): return True + # Don't require for test files + if self.name.startswith("test_"): + return False + # Check if file is in services/ or selectors/ directory if self.module: + # Don't require for test modules + if ".tests." in self.module or ".test." in self.module: + return False # Check if module contains .services. or .selectors., or ends with .services or .selectors if ".services." in self.module or ".selectors." in self.module: return True diff --git a/tests/test_keyword_only_checker.py b/tests/test_keyword_only_checker.py index 8c52103..47e72c3 100644 --- a/tests/test_keyword_only_checker.py +++ b/tests/test_keyword_only_checker.py @@ -477,3 +477,31 @@ def test_top_level_method_checked_nested_not_checked( ) -> None: # Top-level class method is valid, nested class method is not checked assert not violations + + +@pytest.mark.module( + """\ +def test_create_user(username, email): + pass +""", + name="test_user_services", + module="project.app.tests.services", +) +def test_test_files_not_checked( + checker: KeywordOnlyChecker, violations: list[Violation] +) -> None: + assert not violations + + +@pytest.mark.module( + """\ +def util(username, email): + pass +""", + name="utils", + module="project.app.tests.services", +) +def test_test_dirs_not_checked( + checker: KeywordOnlyChecker, violations: list[Violation] +) -> None: + assert not violations