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

    • Improved type-annotation scoring accuracy by excluding Python test files and test_* test functions from evaluation.
  • Documentation

    • Updated “Type Annotations (Static Typing)” criteria to clarify that test files and test_* functions are not included in scoring.
  • Tests

    • Added unit and integration tests covering detection of test file patterns (including Windows-style paths) and verifying assessor behavior for mixed and tests-only repositories.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: d0419a44-2d59-4321-8aea-73f15cab4ebd

📥 Commits

Reviewing files that changed from the base of the PR and between 0c044c1 and dac2946.

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

📝 Walkthrough

Walkthrough

Type annotation scoring now excludes Python test files and test_* functions. The assessor updates file discovery and AST counting, and the docs and tests match the new scoring rules.

Changes

Skip tests in Python type-annotation scoring

Layer / File(s) Summary
Test file detection and docs
src/agentready/assessors/code_quality.py, docs/attributes.md
_is_python_test_file() classifies test files from filename and path patterns, and the attribute docs state that test files and test_* functions are excluded from scoring.
Skip tests during Python scoring
src/agentready/assessors/code_quality.py
Python type-annotation discovery filters out test files from git and filesystem scans, reads sources as UTF-8, and omits test_* functions from AST counts.
Discovery and scoring tests
tests/unit/test_assessors_code_quality.py
Git-backed helpers support assessor discovery tests, and unit cases cover test-path detection, skipped test_* functions, non-test failures, and not_applicable for test-only repositories.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title matches the fix, but it misses the required Conventional Commits scope in type(scope): description format. Rename it to a Conventional Commits title with a scope, such as fix(code-quality): skip test files and test functions in Python type annotations check.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR skips pytest-style test files and test_* functions from Python type annotation scoring, matching issue #385's requirements.
Out of Scope Changes check ✅ Passed The docs update and tests support the stated fix, and no unrelated code changes are evident.
Docstring Coverage ✅ Passed Docstring coverage is 84.62% 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.

@aviavraham aviavraham marked this pull request as ready for review June 8, 2026 13:38
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

📈 Test Coverage Report

Branch Coverage
This PR 75.2%
Main 75.1%
Diff ✅ +0.1%

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

@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.

@jwm4 jwm4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review from Bill Murdock with assistance from Claude Code

Nice work on this fix, @aviavraham. Clean implementation that aligns well with the existing Go _test.go exclusion pattern. The two-layer exclusion (file-level + function-level), the not_applicable handling for test-only repos, and the Windows path normalization are all well done.

There are merge conflicts with main that need resolving. Sorry about that, I believe my recent PR is what caused them. Should be straightforward to rebase.

Once that's resolved, this is good to go.

aviavraham and others added 2 commits June 25, 2026 15:24
…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>
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 aviavraham force-pushed the fix/385-type-annotations-skip-tests branch from 2d942e6 to 0c044c1 Compare June 25, 2026 12:25
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aviavraham

Copy link
Copy Markdown
Contributor Author

@jwm4, the PR is ready to merge

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

2 participants