I am trying to implement unit tests for a function using imported external objects.
For example helpers.py :
import os import pylons def some_func(arg): ... var1 = os.path.exist(...) var2 = os.path.getmtime(...) var3 = pylons.request.environ['HTTP_HOST'] ...
So, when I create a unit test for this, I do some ridicule (minimax in my case) and replacing the links with pylons.request and os.path:
import helpers def test_some_func(): helpers.pylons.request = minimock.Mock("pylons.request") helpers.pylons.request.environ = { 'HTTP_HOST': "localhost" } helpers.os.path = minimock.Mock(....) ... some_func(...)
This does not look good to me.
Is there any other better way or strategy to replace imported function / objects in Python?
source share