Properly introduce test-related rule config when adding pytest#1249
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the timing of when test-related Ruff rules are applied during pytest setup. Previously, Ruff rules were being applied before the /tests directory was created, which meant tools couldn't properly configure glob-based ignores for test directories. The change ensures that:
- The
/testsdirectory is created first viaadd_pytest_dir() - Then all test-related rule configurations from existing tools are collected
- Finally, the combined rule config is applied to Ruff
This allows tools like import-linter to properly configure INP rule ignores for the tests/** glob pattern after the directory exists.
Key changes:
- Moved rule config retrieval and application to after test directory creation
- Added collection of test-related rules from all installed tools via
subset_related_to_tests() - Updated test expectations to reflect the new ordering of operations
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/usethis/_core/tool.py | Refactored use_pytest() to apply rule config after creating test directory, and aggregate test-related rules from all tools |
| src/usethis/_tool/rule.py | Added subset_related_to_tests() method to RuleConfig for filtering test-specific rules |
| tests/usethis/_core/test_core_tool.py | Added integration test verifying INP rules are ignored in tests/** after pytest setup with import-linter |
| tests/usethis/_ui/interface/test_tool.py | Updated expected output to reflect rule selection happening after test directory creation |
| README.md | Updated example output to match new operation ordering |
Comments suppressed due to low confidence (1)
src/usethis/_tool/rule.py:1
- The method creates a copy with
self.model_copy()but then clears all rule lists without actually filtering for test-related rules. The implementation returns an empty RuleConfig instead of a subset of test-related rules. The method should either filter the rules based on test-related criteria, or if this is intentionally returning empty configs for tools that don't have test-related rules, the docstring should clarify this behavior.
from __future__ import annotations
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
CodSpeed Performance ReportMerging #1249 will not alter performanceComparing Summary
|
No description provided.