Repository navigation
Conversation
jpsiddharth2008
left a comment
There was a problem hiding this comment.
Reviewed a7422cb. Please address these before merging:
- Harness isolation:
close()restores override tokens but leaves dependent services cached. A second harness can reuse a closed service holding the previous fake. - Teardown: Track all resolved dependencies in creation order. The current module-instance list misses indirect dependencies and can destroy dependencies before their consumers.
- Factory failure rollback: Include override factory evaluation in the rollback block. A failing factory currently leaves earlier overrides installed.
- Pytest fixture: Resolve
nitro_appdynamically. Checkingrequest.fixturenamesrejects a defined fixture when the test requests onlynitro_client.
I reproduced all four issues independently. Existing focused tests and CI pass, but these cases need regression coverage.
…tories, resolve nitro_app dynamically
|
Thanks for reproducing these. All four are fixed in 2715212, each with a regression test that fails on the old code:
Full suite: 845 passed locally. I dropped the |
jpsiddharth2008
left a comment
There was a problem hiding this comment.
Thanks, the four earlier findings are fixed. One related case remains: if Service is already cached before create(..., overrides={Repo: fake}), it retains the real Repo, so the tool ignores the override.
Please rebuild affected consumers within the harness while preserving the original instances for restoration on close, and add a regression test for this case.
|
Thanks, good catch. Fixed in c1babfc.
Two regression tests, both failing on the previous commit: a consumer resolved before |
…iginals untouched close() found instances to destroy by token, so a consumer rebuilt by create() (same token as the original) was skipped. Compare by object identity instead. Tests now check override, shutdown of rebuilt services and restoration of the originals together, for direct and indirect consumers.
|
Pushed Problem: after Fix: Tests: the direct and indirect consumer tests now check three things together:
Both tests fail on |
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.