Title: agent: tests that set usethis_config attributes directly must use context manager or rely on conftest reset · Issue #1812 · usethis-python/usethis-python · GitHub
Open Graph Title: agent: tests that set usethis_config attributes directly must use context manager or rely on conftest reset · Issue #1812 · usethis-python/usethis-python
X Title: agent: tests that set usethis_config attributes directly must use context manager or rely on conftest reset · Issue #1812 · usethis-python/usethis-python
Description: Lesson learned from PR #1795 (infer dependencies from setup.cfg) When writing tests that set usethis_config.backend or usethis_config.inferred_backend directly (e.g. usethis_config.backend = BackendEnum.poetry), the state persists to sub...
Open Graph Description: Lesson learned from PR #1795 (infer dependencies from setup.cfg) When writing tests that set usethis_config.backend or usethis_config.inferred_backend directly (e.g. usethis_config.backend = Backen...
X Description: Lesson learned from PR #1795 (infer dependencies from setup.cfg) When writing tests that set usethis_config.backend or usethis_config.inferred_backend directly (e.g. usethis_config.backend = Backen...
Opengraph URL: https://github.com/usethis-python/usethis-python/issues/1812
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"agent: tests that set usethis_config attributes directly must use context manager or rely on conftest reset","articleBody":"## Lesson learned from PR #1795 (infer dependencies from setup.cfg)\n\nWhen writing tests that set `usethis_config.backend` or `usethis_config.inferred_backend` directly (e.g. `usethis_config.backend = BackendEnum.poetry`), the state persists to subsequent tests because there is no cleanup. This caused spurious test failures in CI:\n\n- Tests in `TestGetProjectDeps::TestPoetry` and `TestGetDepGroups::TestPoetry` (newly added) set `usethis_config.backend = BackendEnum.poetry` directly inside a `with` block, which left `inferred_backend` stale after the test completed.\n- Subsequent tests that relied on backend auto-detection (e.g. `TestAddDepsToGroup::test_no_pyproject_toml`) received the stale `inferred_backend = poetry` and tried to call the Poetry subprocess, which is broken in the 'min dependencies' CI environment.\n- `TestGetDepGroups::TestPoetry::test_not_read_without_poetry_backend` failed because it set `backend = none` directly (not via context manager), but `inferred_backend` was already cached as `poetry` from prior tests.\n\n## Root cause\n\n`usethis_config.set(backend=...)` (the context manager) saves and restores both `backend` AND `inferred_backend`. Direct attribute assignment (`usethis_config.backend = ...`) only updates `backend`, leaving `inferred_backend` stale. `get_backend()` in `dispatch.py` checks `inferred_backend` first (line 21) before doing any detection, so stale `inferred_backend` poisons all subsequent `get_backend()` calls.\n\n## Fix applied\n\nAdded `usethis_config.backend = BackendEnum(BACKEND_DEFAULT)` and `usethis_config.inferred_backend = None` to the `clear_functools_caches` autouse fixture in `tests/conftest.py`. This ensures clean backend state at the start of each test, preventing cross-test pollution.\n\n## Recommendation\n\n- Always use `usethis_config.set(backend=...)` as a context manager in tests, not direct attribute assignment.\n- When that is not possible, rely on the autouse fixture reset now present in `tests/conftest.py`.","author":{"url":"https://github.com/nathanjmcdougall","@type":"Person","name":"nathanjmcdougall"},"datePublished":"2026-04-04T07:03:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1812/usethis-python/issues/1812"}
| 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:3f016102-e2e1-2306-72d9-fc070ebf9376 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A814:7CA5C:9E9994:DCD4D6:6A4C9F1E |
| html-safe-nonce | 16886f95622ec6d3c7a87217332590d5b1586a4fd25994312658ad3a4d1126da |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODE0OjdDQTVDOjlFOTk5NDpEQ0Q0RDY6NkE0QzlGMUUiLCJ2aXNpdG9yX2lkIjoiMjMzMDcwOTQ4NDM2NjUwMzcxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 05c4462b53a1a2e01d1760680ff0e6dab6aa5ff153ca12cdf3fbb91c925fe5c1 |
| hovercard-subject-tag | issue:4203948735 |
| 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/1812/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1933f4928a760bc81174490a1b50afa380664b566fc01ef61164a5c8632e7401/usethis-python/usethis-python/issues/1812 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1933f4928a760bc81174490a1b50afa380664b566fc01ef61164a5c8632e7401/usethis-python/usethis-python/issues/1812 |
| og:image:alt | Lesson learned from PR #1795 (infer dependencies from setup.cfg) When writing tests that set usethis_config.backend or usethis_config.inferred_backend directly (e.g. usethis_config.backend = Backen... |
| 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 | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| 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 | ae90d426644ca15e89bacceb72e51f4e9dbf85f7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width