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
修補我那麼看好,但沒有我發現幫助解決的,所以我想我只是做一些明顯錯誤的事情,有人可以指出。