derwiki-adroll / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Unit-test discovery and patch target problem #186

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Let's imagine this scenario. 
* root
** folder_a
*** __init__.py
*** folder_b
**** __init__.py
**** x.py
**** y.py

x.py: 

class A:
    def a():
        pass

y.py: 

from x import A

def foo():
    i = A()
    print i

y_test.py:

...

from y import foo
@patch('y.A')
def test_sometest(self, mock):
    foo()
...

What is the expected output? What do you see instead?

1. When I call python -m unittest -p '*_test.py' from the folder_b then 
everything works. Test prints <MagicMock name='A()' id='19568912'> with patch 
decorator and tests prints <x.A instance at 0xd022d8> without patch decorator 

2. When I call python -m unittest -p '*_test.py' from any folder above e.g. root
then patch fails 
File "/usr/local/lib/python2.7/dist-packages/mock-1.0.0-py2.7.egg/mock.py", 
line 1182, in patched
    arg = patching.__enter__()
  File "/usr/local/lib/python2.7/dist-packages/mock-1.0.0-py2.7.egg/mock.py", line 1241, in __enter__
    self.target = self.getter()
  File "/usr/local/lib/python2.7/dist-packages/mock-1.0.0-py2.7.egg/mock.py", line 1403, in <lambda>
    getter = lambda: _importer(target)
  File "/usr/local/lib/python2.7/dist-packages/mock-1.0.0-py2.7.egg/mock.py", line 1087, in _importer
    thing = __import__(import_path)
ImportError: No module named y

and when i remove patch decorator, then test prints <folder_a.folder_b.x.A 
instance at 0x29f7560>

What version of the product are you using? On what operating system?

python 2.7.3
mock 1.0.0
Linux entless 3.2.0-31-generic #50-Ubuntu SMP Fri Sep 7 16:16:45 UTC 2012 
x86_64 x86_64 x86_64 GNU/Linux

Distributor ID: Ubuntu
Description:    Ubuntu 12.04.1 LTS
Release:    12.04
Codename:   precise

Please provide any additional information below.

Original issue reported on code.google.com by alkna...@gmail.com on 3 Nov 2012 at 8:46