So, no one helped me with my problem and I decided to solve it by myself. Here is a micro-lib called surrogate
which allows one to create stubs for non-existing modules.
Lib can be used with mock
like this:
from surrogate import surrogate
from mock import patch
@surrogate('this.module.doesnt.exist')
@patch('this.module.doesnt.exist', whatever)
def test_something():
from this.module.doesnt import exist
do_something()
Firstly @surrogate
decorator creates stubs for non-existing modules, then @patch
decorator can alter them. Just as @patch
, @surrogate
decorators can be used "in plural", thus stubbing more than one module path. All stubs exist only at the lifetime of decorated function.
If anyone gets any use of this lib, that would be great :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…