2012-05-24 11 views
16

私は@patchと試験方法を飾ることにより、プロバイダクラスにパッチを適用しようとした:Pythonの初心者@patchデコレータ問題

class TestMyUnit(unittest.TestCase): 
... 
@patch(provider.Provider,autospec=True) 
def test_init(self, mock_provider): 
    pass 

しかし、私はテストを実行すると、私はエラーを取得:

*@patch(provider.Provider)* 
*File "build\bdist.win32\egg\mock.py", line 1518, in patch* 
*getter, attribute = \_get\_target(target)* 
*File "build\bdist.win32\egg\mock.py", line 1367, in \_get\_target* 
*target, attribute = target.rsplit('.', 1)* 
*AttributeError: class Provider has no attribute 'rsplit'* 
*ERROR: Module: test\_my\_unit could not be imported (file: C:\dev\src\test\_my\_unit.py).* 

何か案は?

答えて

22

クラスの代わりに文字列を使用します。

@patch('provider.Provider', autospec=True) 
def test_init(self, mock_provider): 
    pass 
+0

ありがとうございました。初心者は確かに:-) – bavaza

+0

ありがとうございます。私のために働く! – Scit

+0

ああ、馬鹿馬鹿しいエラー:) thx for help – Regisz