I have some packages that have soft dependencies on other packages with a fall back to a default (simple) implementation.
The problem is that this is very hard to test for using unit tests. I could set up separate virtual environments, but that is hard to manage.
Is there a package or a way to achieve the following: have
import X
work as usual, but
hide_package('X')
import X
will raise an ImportError.
I keep having bugs creep into the fall-back part of my code because it is hard to test this.
It looks a bit dirty, but you can override the
__import__builtin:BTW, have you read PEP 302? It seems that you can make a more robust mechanism with import hooks.