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
のものを使います。
:module.order.get_file_path
とパッチ適用test_load_order_by_number
- を私はSOで探してみましたが、私が見つけた解決策のどれも助けていないので、私は私だけだと思いました明らかに間違ったことを誰かが指摘することができます。