Skip to content

fix: skip test files and test functions in Python type annotations check#493

Open
aviavraham wants to merge 3 commits into
ambient-code:mainfrom
aviavraham:fix/385-type-annotations-skip-tests
Open

fix: skip test files and test functions in Python type annotations check#493
aviavraham wants to merge 3 commits into
ambient-code:mainfrom
aviavraham:fix/385-type-annotations-skip-tests

Conversation

@aviavraham

@aviavraham aviavraham commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #385

  • Skip test files (test_*.py, *_test.py, conftest.py, tests//test/ dirs) from Python type annotation scoring
  • Skip test functions (test_*) inside non-test source files
  • Aligns Python behavior with the existing Go _test.go exclusion
  • Updated docs/attributes.md to document the exclusion

Test plan

  • 16 new tests covering file detection and integration behavior
  • Linting passes (black, isort, ruff)

Summary by CodeRabbit

  • Bug Fixes

    • Type annotation assessment now excludes Python test files and test functions from scoring, improving accuracy of coverage metrics for non-test code.
  • Documentation

    • Updated guidance to clarify that test files and test_* functions are excluded from type-annotation scoring.
  • Tests

    • Added tests to verify exclusion of test files and test functions and assessor behavior when only test files are present.

…eck (ambient-code#385)

Test files (test_*.py, *_test.py, conftest.py, tests/ dirs) and test
functions (test_*) were penalizing repos for missing type hints on code
that doesn't benefit from annotations. Aligns Python behavior with the
existing Go _test.go exclusion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 07d1fa37-be7d-4571-9a2c-9ed266a47b42

📥 Commits

Reviewing files that changed from the base of the PR and between 3097624 and 2d942e6.

📒 Files selected for processing (2)
  • src/agentready/assessors/code_quality.py
  • tests/unit/test_assessors_code_quality.py

📝 Walkthrough

Walkthrough

TypeAnnotationsAssessor now excludes Python test files and test_* functions from type annotation coverage scoring. A new _is_python_test_file helper detects test files by path conventions and filename patterns. File discovery and AST traversal are updated to filter tests, and unit/integration tests and docs verify the behavior.

Changes

Exclude tests from Python type annotation scoring

Layer / File(s) Summary
Test file detection helper and documentation
src/agentready/assessors/code_quality.py, docs/attributes.md
New _is_python_test_file(file_path: str) -> bool classifies test files using filename conventions (test_*.py, *_test.py, conftest.py) and path segments (tests/, test/). Documentation updated to note test file and function exclusion.
Assessment implementation with test exclusion
src/agentready/assessors/code_quality.py
File discovery filters test files from both git ls-files and filesystem fallback paths. AST traversal skips functions starting with test_. File opening uses explicit UTF-8 encoding.
Unit tests for test file detection
tests/unit/test_assessors_code_quality.py
Helper functions _make_py_repo() and _git_add() set up test repositories. TestIsTestFile parametrized tests verify detection of common test patterns (e.g., tests/foo.py, conftest.py, *_test.py) and non-test paths.
Integration tests for assessment with test exclusions
tests/unit/test_assessors_code_quality.py
TestPythonTypeAnnotationsSkipTests validates that typed source passes while untyped tests/ code is excluded, test_* functions in source are skipped, untyped non-test code fails, and repos with only test files yield not_applicable.

Suggested labels: released

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title follows Conventional Commits format (fix: description) and accurately summarizes the main change: excluding test files and test functions from Python type annotations scoring.
Linked Issues check ✅ Passed The PR fully implements issue #385 requirements: excludes test files (test_*.py, test.py, conftest.py, tests/ and test/ directories) and test functions (test) from type annotation scoring, with comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #385: code modifications to TypeAnnotationsAssessor, documentation updates, and corresponding test coverage. No unrelated changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@aviavraham aviavraham marked this pull request as ready for review June 8, 2026 13:38
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

📈 Test Coverage Report

Branch Coverage
This PR 73.8%
Main 73.8%
Diff ✅ +0%

Coverage calculated from unit tests only

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/agentready/assessors/code_quality.py`:
- Around line 162-176: _is_python_test_file currently uses PurePosixPath which
doesn't split Windows backslash separators, so normalize the incoming file_path
by replacing backslashes with forward slashes (e.g., file_path =
file_path.replace("\\\\", "/")) before constructing PurePosixPath or split
parts; update the _is_python_test_file function to perform this normalization
(or alternatively use pathlib.PurePath with explicit normalization) so names
like "tests\\test_app.py" are correctly detected as test files while preserving
the existing name/parts checks (references: function _is_python_test_file,
PurePosixPath).

In `@tests/unit/test_assessors_code_quality.py`:
- Around line 39-65: Add Windows-style path variants to the test cases for
TypeAnnotationsAssessor._is_python_test_file: update the parameter list used by
test_identifies_test_files to include at least "tests\\test_foo.py" (and
optionally "test\\test_bar.py") so the underscore method is validated on
backslash-separated paths; keep the test_identifies_non_test_files list
unchanged unless you want to add non-test backslash examples similarly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: bf718a70-e4e1-4998-b7eb-87e04829136f

📥 Commits

Reviewing files that changed from the base of the PR and between 0fd1975 and 7681bf8.

📒 Files selected for processing (3)
  • docs/attributes.md
  • src/agentready/assessors/code_quality.py
  • tests/unit/test_assessors_code_quality.py

Comment thread src/agentready/assessors/code_quality.py
Comment thread tests/unit/test_assessors_code_quality.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
tests/unit/test_assessors_code_quality.py (1)

40-51: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add Windows-style path cases to lock in cross-platform test-file detection

Line 43-Line 51 only validate POSIX-style separators. Add at least one backslash path (e.g., tests\\test_foo.py) so _is_python_test_file behavior is enforced for Windows-style paths too; this is the key edge case for path-based exclusion logic.

Suggested minimal test update
     `@pytest.mark.parametrize`(
         "path",
         [
             "tests/test_foo.py",
             "test/test_bar.py",
             "tests/unit/test_baz.py",
             "src/tests/test_helpers.py",
+            r"tests\test_win.py",
+            r"test\unit\test_bar.py",
             "test_something.py",
             "foo_test.py",
             "conftest.py",
             "tests/conftest.py",
         ],
     )

As per coding guidelines, “tests/**: Check for missing edge cases.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/test_assessors_code_quality.py` around lines 40 - 51, The
parametric test only covers POSIX-style paths; add at least one Windows-style
path with backslashes (for example "tests\\test_foo.py") to the
pytest.mark.parametrize "path" list so the _is_python_test_file behavior is
validated on Windows separators as well; update the list of test cases in
tests/unit/test_assessors_code_quality.py (the pytest parametrization block) to
include the backslash variant.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@tests/unit/test_assessors_code_quality.py`:
- Around line 40-51: The parametric test only covers POSIX-style paths; add at
least one Windows-style path with backslashes (for example "tests\\test_foo.py")
to the pytest.mark.parametrize "path" list so the _is_python_test_file behavior
is validated on Windows separators as well; update the list of test cases in
tests/unit/test_assessors_code_quality.py (the pytest parametrization block) to
include the backslash variant.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 5d72f872-bda9-4c05-a349-a47dbdd9e3b1

📥 Commits

Reviewing files that changed from the base of the PR and between 7681bf8 and 3097624.

📒 Files selected for processing (1)
  • tests/unit/test_assessors_code_quality.py

Addresses CodeRabbit review: PurePosixPath doesn't split Windows
backslash separators, so normalize before classification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aviavraham

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Type Annotations should skip tests

1 participant