Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
3602 Lượt xem

I would like to import the mock-library in odoo testing environment. I use 

import unittest.mock

but when using @mock.patch I get a NameError: name 'mock' is not defined.

What's the problem?


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

yes, you can use it. unittest is part of a standard python.

I think your import statement is incorrect

try:
  from unittest.mock import patch
except ImportError:    
  from mock import patch

use @patch

Ảnh đại diện
Huỷ bỏ
Tác giả

That's it! Thanks!