Repository navigation
Put the pytest plugin's container in test mode from the start - #333
Merged
Merged
Conversation
Test mode was switched on only when the `container` fixture ran, so a conftest overriding through the imported container warned on every override until some test happened to request the fixture, and the number of warnings depended on test order. The container named by `anydi_container` now enters test mode in `pytest_configure`, and a global container created while the tests are collected enters it before the first fixture runs. Test mode is turned off and the replaced global container restored at session end. A container from a project's own `container` fixture still enters test mode when the fixture first runs. A new `anydi` ini flag, on by default, turns the plugin off when set to false: no `container` fixture, no injection, the container left alone.
Contributor
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The plugin enabled test mode only when the
containerfixture was set up. A conftest that overrides through the imported container (withanydi_containerset) never requests that fixture, so everyoverride()warned withUsing override() without enabling test modeuntil some test happened to takecontainer. The warning count, and whether the override cache was active, depended on test order and filtering.Changes
anydi_containeris loaded inpytest_configureand put in test mode there. A bad path is a usage error naming the setting.pytest_collection_finish, before any fixture runs.pytest_unconfigureturns test mode off on the containers the plugin enabled and restores the global container it replaced, so an in-process second run starts clean.containerfixture keeps working. Its container enters test mode when the fixture first runs, as before. Theanydi_djangofallback stays lazy.anydiini flag, defaulttrue. Withanydi = falsethe plugin registers no fixtures or hooks: nocontainerfixture, no injection, test mode and the global container untouched.docs/usage/testing.md.Tests
New
pytestertests: plugin disabled, overrides from a conftest with-W error::UserWarningin both test orders, a global container created at collection, an invalidanydi_container, cleanup after the session. All fail on the previous plugin. The plugin test run now also passes-p pytester(Makefile and CI).