Skip to content

Properly introduce test-related rule config when adding pytest#1249

Merged
nathanjmcdougall merged 4 commits intomainfrom
1234-ignore-inp-rules-in-a-newly-created-tests-directory
Dec 30, 2025
Merged

Properly introduce test-related rule config when adding pytest#1249
nathanjmcdougall merged 4 commits intomainfrom
1234-ignore-inp-rules-in-a-newly-created-tests-directory

Conversation

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

No description provided.

@nathanjmcdougall nathanjmcdougall linked an issue Dec 29, 2025 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 /tests directory is created first via add_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
Copy link
Copy Markdown

codecov bot commented Dec 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Dec 29, 2025

CodSpeed Performance Report

Merging #1249 will not alter performance

Comparing 1234-ignore-inp-rules-in-a-newly-created-tests-directory (112b2f4) with main (397d419)

Summary

✅ 2 untouched

@nathanjmcdougall nathanjmcdougall merged commit d6180f3 into main Dec 30, 2025
19 checks passed
@nathanjmcdougall nathanjmcdougall deleted the 1234-ignore-inp-rules-in-a-newly-created-tests-directory branch December 30, 2025 03:25
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.

Ignore INP rules in a newly-created tests directory

2 participants