Title: Lesson: Tests for a class method should live in the test file for that class · Issue #1895 · usethis-python/usethis-python · GitHub
Open Graph Title: Lesson: Tests for a class method should live in the test file for that class · Issue #1895 · usethis-python/usethis-python
X Title: Lesson: Tests for a class method should live in the test file for that class · Issue #1895 · usethis-python/usethis-python
Description: 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 wr...
Open Graph Description: 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_...
X Description: 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_...
Opengraph URL: https://github.com/usethis-python/usethis-python/issues/1895
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Lesson: Tests for a class method should live in the test file for that class","articleBody":"## Context\n\nWhen 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`.\n\n## Root Cause\n\nThe 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`.\n\n## Principle\n\n**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`.\n\n## Affected Skills\n\nThe `usethis-python-test` skill should include guidance on test placement: always match test class structure to the source class hierarchy.","author":{"url":"https://github.com/nathanjmcdougall","@type":"Person","name":"nathanjmcdougall"},"datePublished":"2026-04-08T02:54:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1895/usethis-python/issues/1895"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d770da34-43b1-57da-04d7-00cd7f801800 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BE1E:8377:2525D88:347E7B5:6A4CE2EA |
| html-safe-nonce | 1abb13cf3e3387a6decf3514378cec2d099a104d5bb3d42f2eb25d9333d829f9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTFFOjgzNzc6MjUyNUQ4ODozNDdFN0I1OjZBNENFMkVBIiwidmlzaXRvcl9pZCI6IjU0NzgzNzUxMTQ3ODMzODI4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 90c6fe6e1b7f9dd4ab33579901312263c3ba9eb941f427e46272c52affdfd13e |
| hovercard-subject-tag | issue:4221759659 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/usethis-python/usethis-python/1895/issue_layout |
| twitter:image | https://opengraph.githubassets.com/74de898ca162cac703314c2626c49daf5ccf9b0350dfac399ae01cbc5032af61/usethis-python/usethis-python/issues/1895 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/74de898ca162cac703314c2626c49daf5ccf9b0350dfac399ae01cbc5032af61/usethis-python/usethis-python/issues/1895 |
| og:image:alt | 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_... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nathanjmcdougall |
| hostname | github.com |
| expected-hostname | github.com |
| None | 299b43bca6e02ad35197ffeba30d2466846d5fb02ab96fbced5b5e6cec589fb8 |
| turbo-cache-control | no-preview |
| go-import | github.com/usethis-python/usethis-python git https://github.com/usethis-python/usethis-python.git |
| octolytics-dimension-user_id | 216362695 |
| octolytics-dimension-user_login | usethis-python |
| octolytics-dimension-repository_id | 842189705 |
| octolytics-dimension-repository_nwo | usethis-python/usethis-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 842189705 |
| octolytics-dimension-repository_network_root_nwo | usethis-python/usethis-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c5a57f04eeb310f57c73fd6d751d957e2ca27ed2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width