Skip to content

Lesson: Tests for a class method should live in the test file for that class #1895

Description

@nathanjmcdougall

Context

When adding validated_get and ensure_get methods to KeyValueFileManager, the tests for these methods were placed in tests/usethis/_file/test_validate.py instead of tests/usethis/_file/test_manager.py.

Root Cause

The tests were written near the validate_or_raise/validate_or_default tests since they use similar validation functionality. However, these methods are defined on KeyValueFileManager (in manager.py), not in validate.py.

Principle

Tests for a class method should live in the test file for that class, not in the test file for the utilities the method uses internally. The test file structure should mirror the source file structure. If a method is defined on KeyValueFileManager in manager.py, its tests belong under TestKeyValueFileManager in test_manager.py.

Affected Skills

The usethis-python-test skill should include guidance on test placement: always match test class structure to the source class hierarchy.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentConfiguration updates for LLM coding agents

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions