flask-testing
flask-testing copied to clipboard
Cannot mock subprocess because twill has it's own.
One of my tests look like this:
def test_get_network_info(self):
with patch('subprocess.check_output', Mock(return_value=values)):
And gives the following error:
======================================================================
ERROR: test_get_network_info (tests.test_tools.ToolsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/tim/Documents/overseer/app/tests/test_tools.py", line 21, in test_get_network_info
with patch('subprocess.check_output', Mock(return_value=mock_network_info.read())):
File "/usr/local/lib/python2.7/dist-packages/mock.py", line 1268, in __enter__
original, local = self.get_original()
File "/usr/local/lib/python2.7/dist-packages/mock.py", line 1242, in get_original
"%s does not have the attribute %r" % (target, name)
AttributeError: <module 'subprocess' from '/usr/local/lib/python2.7/dist-packages/twill/other_packages/subprocess.pyc'> does not have the attribute 'check_output'
My understanding of the problem is that mock
is trying to mock twill's subprocess
module instead of the python one.
Am I doing something wrong ? Should I try to patch the subprocess
module differently ?
Here is the twill's version of subprocess wich looks like it has been copy pasted from an old version of python ? https://github.com/ctb/twill/blob/master/twill/other_packages/subprocess.py
I don't even understand why twill need his own subprocess
module ...
https://github.com/ctb/twill/search?q=subprocess&ref=cmdform
It seems to work fine if you remove the twill/other_packages/subprocess.py*
files.