Skip to content

Commit 569bb5f

Browse files
author
Morten Krane
authored
fix: Exclude tests from keyword-only checker (#30)
* Skip keyword checks in tests * Add tests
1 parent bd5da14 commit 569bb5f

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

oida/checkers/services.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,15 @@ def _check_if_service_or_selector(self) -> bool:
6060
if self.name in ("services", "selectors"):
6161
return True
6262

63+
# Don't require for test files
64+
if self.name.startswith("test_"):
65+
return False
66+
6367
# Check if file is in services/ or selectors/ directory
6468
if self.module:
69+
# Don't require for test modules
70+
if ".tests." in self.module or ".test." in self.module:
71+
return False
6572
# Check if module contains .services. or .selectors., or ends with .services or .selectors
6673
if ".services." in self.module or ".selectors." in self.module:
6774
return True

tests/test_keyword_only_checker.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,31 @@ def test_top_level_method_checked_nested_not_checked(
477477
) -> None:
478478
# Top-level class method is valid, nested class method is not checked
479479
assert not violations
480+
481+
482+
@pytest.mark.module(
483+
"""\
484+
def test_create_user(username, email):
485+
pass
486+
""",
487+
name="test_user_services",
488+
module="project.app.tests.services",
489+
)
490+
def test_test_files_not_checked(
491+
checker: KeywordOnlyChecker, violations: list[Violation]
492+
) -> None:
493+
assert not violations
494+
495+
496+
@pytest.mark.module(
497+
"""\
498+
def util(username, email):
499+
pass
500+
""",
501+
name="utils",
502+
module="project.app.tests.services",
503+
)
504+
def test_test_dirs_not_checked(
505+
checker: KeywordOnlyChecker, violations: list[Violation]
506+
) -> None:
507+
assert not violations

0 commit comments

Comments
 (0)