Skip to content

Tighten test assertions: drop dead asserts, relax cycle-rotation check, capture warnings, exercise union arm#196

Merged
lesnik512 merged 1 commit into
mainfrom
nice-to-have-test-improvements
Jun 5, 2026
Merged

Tighten test assertions: drop dead asserts, relax cycle-rotation check, capture warnings, exercise union arm#196
lesnik512 merged 1 commit into
mainfrom
nice-to-have-test-improvements

Conversation

@lesnik512
Copy link
Copy Markdown
Member

Summary

Five test-quality improvements from the 2026-06-05 bug-hunt audit (nice-to-have items #5, #6, #9, #10, #14). No source code changes.

  • Injecting factory itself #5 `test_container_resolve_missing_provider`: Dropped `assert app_container.resolve(str) is None` — the call raises before the comparison runs, so the assert was dead code that would have hidden a regression where `resolve` started returning None instead of raising.
  • Add Litestar integration #6 `test_func_with_union_factory`: Replaced `assert instance1` (passes for any non-empty string) with `assert instance1 == str(SimpleCreator(dep1='original'))`. Now actually exercises which arm of the `SimpleCreator | int` union was selected — changing the creator to return `'X'` would correctly fail this test.
  • add LiteStar integration #9 `test_func_with_broken_annotation`: Moved Factory construction inside the test body, wrapped in `pytest.warns(UserWarning, match='Failed to resolve type hints')`. Now verifies the `UserWarning` from `parse_creator`'s `NameError` branch is actually emitted — removing the `warnings.warn(...)` call in `types_parser` would now fail this test.
  • Add LiteStar Example #10 `test_validate_detects_cycle`: Replaced `assert cycle_path == ['CycleA', 'CycleB', 'CycleA']` (depends on Group declaration order) with rotation-independent checks: `cycle[0] == cycle[-1]` and `set(cycle) == {'CycleA', 'CycleB'}`. Swapping the declaration order of `a` and `b` in `CycleGroup` no longer breaks the test.
  • implement factories injecting #14 `test_alias_resolve_provider`: Deleted. The sibling `test_alias_delegates_to_source` already performs the load-bearing `concrete is abstract` identity check; this test only asserted `isinstance`, which would pass even with `Alias.resolve` broken to construct a fresh instance.

Also dropped the now-unused module-level `func_with_broken_annotation` Factory registration in `MyGroup` since #9 moved it into the test body.

Test plan

  • Updated tests pass; deleted test gone; full suite green (146 passed).
  • 100% coverage maintained.
  • `just lint-ci` green.

🤖 Generated with Claude Code

@lesnik512 lesnik512 self-assigned this Jun 5, 2026
@lesnik512 lesnik512 merged commit 582c452 into main Jun 5, 2026
6 of 7 checks passed
@lesnik512 lesnik512 deleted the nice-to-have-test-improvements branch June 5, 2026 20:03
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.

1 participant