0
我觉得这应该是一个简单的模拟,但我还没有得到它的工作。功能补丁不被进口模块拾取
我工作过以下目录结构:
module
├── utilities.py
├── order.py
├── test
│ ├── test_order.py
相关的代码如下:
- utilities.py -
def get_file_path(order_number, file_extension):
# this is what I want to mock out
- 秩序。 py -
from module.utilities import get_file_path
class Order():
# ...
@classmethod
def load_order(order_number, extension):
file_path = get_file_path(order_number, extension)
- test_order.py -
import unittest
from unittest.mock import patch
from module.order import order
@patch('order.get_file_path')
def mock_file(_, extension):
if extension == 'json':
return static_file_path
class TestOrder(unittest.TestCase):
def test_load_order_by_number(self):
my_order = order.load_order(number, extension)
这是我第一次尝试在Python中进行模拟。据我所知,我有什么应该工作,但每当Order
调用get_file_path
时,它总是使用utilities.py
中的那个。
我曾尝试:
- 装饰
test_load_order_by_number
- 与
module.order.get_file_path
修补我那么看好,但没有我发现帮助解决的,所以我想我只是做一些明显错误的事情,有人可以指出。