Using NSubstitute for Partial Mocks

See the original posting on DZone Python

I have previously written about how to, effectively, subclass using NSubstitute; in this post, I’ll cover how to partially mock out that class.

Before I get into the solution, what follows is a workaround to allow badly written or legacy code to be tested without refactoring. If you’re reading this and thinking you need this solution then my suggestion would be to refactor and use some form of dependency injection. However, for various reasons, that’s not always possible (hence this post).