flask-testing icon indicating copy to clipboard operation
flask-testing copied to clipboard

Cannot mock subprocess because twill has it's own.

Open TimotheeJeannin opened this issue 11 years ago • 2 comments

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

TimotheeJeannin avatar Dec 22 '13 11:12 TimotheeJeannin

I don't even understand why twill need his own subprocess module ...

https://github.com/ctb/twill/search?q=subprocess&ref=cmdform

TimotheeJeannin avatar Dec 22 '13 11:12 TimotheeJeannin

It seems to work fine if you remove the twill/other_packages/subprocess.py* files.

srossross avatar Apr 16 '14 16:04 srossross