Skip to content

fix: reject a provider named like the container fixture in expose() - #69

Merged
lesnik512 merged 1 commit into
mainfrom
fix/67-container-fixture-collision
Oct 17, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
fix/67-container-fixture-collision

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Closes #67

expose() now raises ValueError when a provider's attribute name equals the container_fixture name in use (di_container by default, or whatever is passed). Before this, the generated fixture replaced the user's container fixture, every generated fixture then depended on itself, and each test failed with a recursive dependency error that did not point at the cause.

The error message names the group, the attribute, and the container fixture, and suggests renaming the provider or passing a different container_fixture.

Design notes:

  • The check lives in _collect_fixtures, next to the existing duplicate-name check, so it runs before anything is installed on the module and can name the offending group. _collect_fixtures gains a keyword-only container_fixture argument defaulting to di_container, matching expose().
  • I used plain ValueError for consistency with the duplicate-name collision. The modern-di exception types are about container registration and do not fit a fixture naming problem.
  • A provider named di_container is still allowed when a different container_fixture is passed, since nothing collides in that case.
  • Collisions with pytest built-in or other existing fixtures are out of scope (expose() silently overwrites a name already defined in the conftest #68).

Tests: three new cases in tests/test_expose.py (default name, custom name, and the no-collision case with a custom name). The first two failed before the fix. README's expose section mentions the new error.

@lesnik512
lesnik512 merged commit 1a5e968 into main Oct 17, 2026
12 checks passed
@lesnik512
lesnik512 deleted the fix/67-container-fixture-collision branch October 17, 2026 09:58
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.

A provider named di_container replaces the container fixture and makes every exposed fixture recursive

1 participant