3 ms·
What about when there's some environment-specific (or otherwise problematic) dependency that you need to mock because it can't be imported where you want to run
by ptx 5y ago
What about when there's some environment-specific (or otherwise problematic) dependency that you need to mock because it can't be imported where you want to run the unit tests? Patching it afterwards doesn't work when the import of the default implementation fails.
If you patch it ahead of time by inserting a dummy module, that dummy module might be used to initialize other modules that you weren't targeting, so undoing the patch after the test might be very tricky.
You can sort of make it work, but it seems really hacky, so for that reason I'm currently refactoring towards DI (without frameworks). But I'm open to better ideas.