Skip to content

fix: detect PascalCase compiled-language tests and root-level conftest.py - #874

Merged
anderdc merged 3 commits into
entrius:testfrom
polyjeff529:fix/is-test-file-pascalcase-and-rootlevel-conftest
May 5, 2026
Merged

fix: detect PascalCase compiled-language tests and root-level conftest.py#874
anderdc merged 3 commits into
entrius:testfrom
polyjeff529:fix/is-test-file-pascalcase-and-rootlevel-conftest

Conversation

@polyjeff529

Copy link
Copy Markdown
Contributor

Summary

FileChange.is_test_file() missed two real-world test naming conventions, so legitimate test files were being scored as production source.

#866 — PascalCase compiled-language tests

JUnit / Kotlin / MSTest / XCTest / ScalaTest commonly use <ClassName>Test.<ext> or <ClassName>Tests.<ext>. Examples that previously slipped through:

  • app/src/main/java/com/example/AccountServiceTest.java
  • app/src/main/kotlin/com/example/UserRepositoryTests.kt
  • MyApp/Tests/AuthFlowTests.swift
  • src/MyProject.Tests/CheckoutTests.cs
  • core/src/main/scala/com/example/PaymentTest.scala

The existing _test\.[ext]$ patterns only fire on snake_case, so Foo_test.kt matched but FooTest.kt did not.

The matcher needs to distinguish FooTest.kt (test) from Latest.kt / Manifest.java (not test). The capital T is the disambiguator, but the existing implementation lowercases the basename before matching, which erases it. The new pattern uses the original-case basename and requires [A-Z][A-Za-z0-9]*Tests?\.(swift|kt|java|cs|scala)$.

#865 — root-level / package-level conftest.py

pytest's fixture file is treated as a test by pytest regardless of where it lives in the tree. Previously only conftest.py files inside a tests/ directory were classified as tests; ones at the project root or alongside a package (a common pytest layout) were scored as production code.

Added an early return on basename == 'conftest.py'.

Tests

Three new parametrized blocks in tests/test_classes.py:

  • test_is_test_file_detects_pascalcase_compiled_language_tests — 9 cases across Java / Kotlin / Swift / C# / Scala
  • test_is_test_file_rejects_pascalcase_lookalikes — guards against Latest.kt, Manifest.java, latest.md, contest.css
  • test_is_test_file_detects_conftest_at_any_depth — root, tests/, package-level, deeply nested

Existing detection cases (gradle source sets, rspec, non-test lookalikes, snake_case _test/_spec/.test) all still pass.

Test plan

  • pytest tests/test_classes.py — 42 passed
  • ruff check gittensor/classes.py tests/test_classes.py — clean
  • ruff format --check — clean

Closes #866
Closes #865

…t.py

is_test_file() missed two common conventions:

- PascalCase test names in compiled languages (FooTest.java, FooTests.kt,
  AccountServiceTests.cs, FooTests.swift, FooTest.scala). Detection uses
  the original-case basename so the capital-T boundary distinguishes them
  from incidental words like Latest.kt or Manifest.java.
- conftest.py outside a tests/ directory (e.g. at the project root or
  inside a package), which pytest treats as a fixture file project-wide.

Closes entrius#866
Closes entrius#865
@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label Apr 30, 2026

@anderdc anderdc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Scope this down to two pattern-list additions:

test_dir_patterns = [
    ...
    r'\.tests?/',           # .NET MyProject.Tests/FooTests.cs
]
test_patterns = [
    ...
    r'^conftest\.py$',
]

Drop the basename_original variable and the [A-Z][A-Za-z0-9]*Tests?\.(swift|kt|java|cs|scala)$ regex. The \.tests?/ directory pattern covers the meaningful #866 case (.NET test-project layout — MyProject.Tests/FooTests.cs doesn't match the existing (^|/)tests?/ because the segment is MyProject.Tests, not tests). The remaining co-located FooTest.kt layout the basename regex catches is rare enough not to justify a second case-sensitivity rule in the function — and the leading [A-Z] requirement excludes fooTest.cs, which #866 explicitly lists as a missed case.

Tests can shrink to match: keep conftest-at-any-depth and .Tests/ directory cases; the co-located PascalCase fixtures aren't needed.

…review

Per anderdc's review on entrius#874:

- Replace the conftest.py early-return with a r'^conftest\.py$' entry in
  test_patterns so the shared regex loop owns the match.
- Replace the trailing PascalCase basename regex with a r'\.tests?/' entry
  in test_dir_patterns. This covers the meaningful entrius#866 case (.NET layout
  MyProject.Tests/FooTests.cs, which doesn't match the existing
  (^|/)tests?/ because the segment is MyProject.Tests, not tests). The
  co-located FooTest.kt layout the basename regex covered is rare enough
  not to justify a second case-sensitivity rule, and the previous
  [A-Z][A-Za-z0-9]*Tests?\. anchor would have excluded fooTest.cs that
  entrius#866 explicitly listed as a missed case.
- Drop the basename_original variable now that no original-case match
  remains.

Tests shrunk to match: keep conftest-at-any-depth and the .Tests/
directory cases; drop the co-located PascalCase fixtures and the
PascalCase-lookalike rejects.
@polyjeff529

Copy link
Copy Markdown
Contributor Author

Scope this down to two pattern-list additions:

test_dir_patterns = [
    ...
    r'\.tests?/',           # .NET MyProject.Tests/FooTests.cs
]
test_patterns = [
    ...
    r'^conftest\.py$',
]

Drop the basename_original variable and the [A-Z][A-Za-z0-9]*Tests?\.(swift|kt|java|cs|scala)$ regex. The \.tests?/ directory pattern covers the meaningful #866 case (.NET test-project layout — MyProject.Tests/FooTests.cs doesn't match the existing (^|/)tests?/ because the segment is MyProject.Tests, not tests). The remaining co-located FooTest.kt layout the basename regex catches is rare enough not to justify a second case-sensitivity rule in the function — and the leading [A-Z] requirement excludes fooTest.cs, which #866 explicitly lists as a missed case.

Tests can shrink to match: keep conftest-at-any-depth and .Tests/ directory cases; the co-located PascalCase fixtures aren't needed.

I updated, Could you check it?

@anderdc
anderdc merged commit 0f437d0 into entrius:test May 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

2 participants