Skip to content

fix: filter test_*.py files and pytest fixtures from optimization#1471

Merged
KRRT7 merged 3 commits intomainfrom
fix-test-function-filtering
Feb 12, 2026
Merged

fix: filter test_*.py files and pytest fixtures from optimization#1471
KRRT7 merged 3 commits intomainfrom
fix-test-function-filtering

Conversation

@KRRT7
Copy link
Collaborator

@KRRT7 KRRT7 commented Feb 12, 2026

Summary

  • Add test_*.py prefix and conftest.py patterns to is_test_file() for the overlapping tests_root case
  • Add @pytest.fixture filtering in libcst FunctionVisitor to exclude fixtures from discovery
  • Add tests for both changes

Fixes test functions being optimized when tests-root = "." (e.g., test_fallback_agent.py in test_unst_prop/ directory).

Test plan

  • test_filter_functions_python_test_prefix_convention — verifies test_*.py and conftest.py filtering
  • test_pytest_fixture_not_discovered — verifies all forms of @pytest.fixture are excluded
  • All 23 existing discovery tests pass

KRRT7 and others added 3 commits February 12, 2026 16:59
When tests_root overlaps with module_root (e.g., both set to "."),
the pattern matching in is_test_file() missed Python's standard
test_*.py naming convention and conftest.py files. Also adds pytest
fixture filtering in the libcst FunctionVisitor to prevent fixtures
from being discovered as optimizable functions.
@claude
Copy link
Contributor

claude bot commented Feb 12, 2026

PR Review Summary

Prek Checks

Fixed: 2 formatting issues resolved and pushed:

  • tests/test_function_discovery.py: Inconsistent indentation on line 1210 (extra spaces before project_root=temp_dir)
  • codeflash/discovery/functions_to_optimize.py: Trailing blank lines at end of file

All checks now pass (ruff check + ruff format).

Mypy

All mypy errors in the changed files are pre-existing (not introduced by this PR). The source file errors are in unchanged lines, and the test file errors (missing -> None return types) follow the same pattern as existing tests in the file.

Code Review

No critical issues found. The changes are well-structured:

  • is_pytest_fixture method: Correctly handles all decorator forms (@pytest.fixture, @pytest.fixture(), @fixture, @fixture(), @pytest.fixture(scope=...)) by unwrapping cst.Call nodes before checking the underlying reference.
  • is_test_file additions: Properly uses basename (not full path) to check test_* prefix, avoiding false positives on files like contest.py or directories like /home/user/tests/myproject/.
  • Defense in depth: File-level filtering (conftest.py, test_*.py) catches test files early, while function-level filtering (is_pytest_fixture) handles fixtures in non-test files via the libcst path.
  • Note: The AST-based FunctionWithReturnStatement visitor does not have fixture filtering, but this is acceptable since the file-level filter handles conftest.py and test files before function discovery.

Test Coverage

File Main PR Change
codeflash/discovery/functions_to_optimize.py 59% 69% +10%
tests/test_function_discovery.py 100% 100% No change
  • All new lines are covered by tests (lines 81-92 is_pytest_fixture, line 97 fixture check, lines 844-851 is_test_file additions)
  • 2 new tests added: test_filter_functions_python_test_prefix_convention and test_pytest_fixture_not_discovered
  • All 14 tests in test_function_discovery.py pass (12 existing + 2 new)
  • Coverage increased by 10% on the modified source file

Codeflash Optimization PRs

Checked 7 open optimization PRs targeting main. All have failing CI — none eligible for merge.


Last updated: 2026-02-12T17:30 UTC

@KRRT7 KRRT7 merged commit 4a978b1 into main Feb 12, 2026
27 of 28 checks passed
@KRRT7 KRRT7 deleted the fix-test-function-filtering branch February 12, 2026 22:34
KRRT7 added a commit that referenced this pull request Feb 19, 2026
fix: filter test_*.py files and pytest fixtures from optimization
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.

1 participant

Comments