Repository navigation
Conversation
This branch has not been deployed
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.
Closes #74
What this adds
NitroTestingModule.create(AppModule, overrides={Token: instance_or_factory}). An instance is used as is; a class or plain function is called with no arguments (it may beasync). The overrides are registered before the app is built, so the original provider is never constructed.await harness.close()andasync with.close()calls each provider'son_module_destroyhook (sync or async) once, in reverse creation order, then removes the overrides from the DI container so the next test starts clean. It is idempotent, and every hook runs even if one fails (the first error is raised afterwards). Overrides are also undone ifcreate()itself fails.MockLogger(has_log(level, message),clear()),create_mock_context(**overrides)andflush_tasks(), all innitrostack.testing.nitro_clientinnitrostack.testing.pytest_plugin, selected with@pytest.mark.nitro_app(module=Root)or anitro_appfixture, and closed after the test. This replaces the old PR feat: expand security, background tasks, and dev tooling #4 fixture; the marker takesmodule=because pytest treats a lone class passed to a marker as a decoration.tests/test_readme_examples.pyruns every README block marked<!-- readme-test -->.Notes
on_module_destroy. Say if you prefer a different name.McpApplicationnow keeps_module_instances(used byclose()) and skipsunittest.mockobjects when it scans providers for tools. AMagicMockanswershasattrfor everything, so without this it was registered as a tool.Tests
tests/test_testing_module_overrides.py(15 tests) andtests/test_readme_examples.py(2): override used and original never built, factory forms, close once when called twice,async with, overrides restored (also after a failed create), failing hook,MagicMockoverrides, logger, context,flush_tasks, the fixture, and no warnings with-W error. Full suite: 841 passed locally.