I have a Python function inside of a class that runs a Photoshop script with the subprocess module.
def runPhotoshop(self):
photoshop = r'C:\Program Files\Adobe\Adobe Photoshop CC 2014\Photoshop.exe'
extendscript = os.path.join(os.getcwd(), 'someScript.jsx')
returnCode = subprocess.call([photoshop, extendscript])
return returnCode
Firing up Photoshop every time I fire off a unit test is expensive, so I decided to use mock. The MyTool class was imported from the mytool module earlier.
@mock.patch('mytool.subprocess')
def test_run_tool(self, mock_subprocess):
# Need instance inside the test for patch to work
tool = MyTool()
# Patch in a mock subprocess module
mock_subprocess.call.return_value = 0
# Run the function and test the return value
returnCode = mytool.runPhotoshop()
self.assertEqual(returnCode, 0, "Javascript was not successful")
# Was the subprocess function called?
photoshop = r'C:\Program Files\Adobe\Adobe Photoshop CC 2014\Photoshop.exe'
extendscript = os.path.join(os.getcwd(), 'someScript.jsx')
mock_subprocess.call.assert_called_with([photoshop, extendscript])
This test works perfectly when ran from the command line (a Windows Powershell), and Photoshop never launches which is what I want..
In method test_add_metadata_to_image_file
.
----------------------------------------------------------------------
Ran 1 test in 0.016s
OK
However, when I run the same unit test inside the PyDev plugin for Eclipse Helios, not only does Photoshop launches, but I get an assertion error:
AssertionError: Expected call: call(['C:\\Program Files\\Adobe\\Adobe Photoshop CC 2014\\Photoshop.exe', 'D:\\work_directory\\someScript.jsx'])
Not called
This is not the first time I noticed a difference between running a unit test in PyDev versus the command line. In fact, I am considering not running tests anymore in PyDev and just stick to the command line (less variables). However, I would like to have an idea of what is going on.