【发布时间】:2021-03-19 17:02:36
【问题描述】:
我在正确修补 pytest 中的导入函数时遇到问题。我要修补的函数是一个旨在执行大型 SQL 提取的函数,因此为了提高速度,我想用读取 CSV 文件来替换它。这是我目前拥有的代码:
from data import postgres_fetch
import pytest
@pytest.fixture
def data_patch_market(monkeypatch):
test_data_path = os.path.join(os.path.dirname(__file__), 'test_data')
if os.path.exists(test_data_path):
mock_data_path = os.path.join(test_data_path, 'test_data_market.csv')
mock_data = pd.read_csv(mock_data_path)
monkeypatch.setattr(postgres_fetch, 'get_data_for_market', mock_data)
def test_mase(data_patch_market):
data = postgres_fetch.get_data_for_market(market_name=market,
market_level=market_level,
backtest_log_ids=log_ids,
connection=conn)
test_result= build_features.MASE(data)
但是,当我运行此测试时,我收到有关调用 DataFrame 的类型错误:
TypeError: 'DataFrame' object is not callable
我知道 csv 可以正确读取,因为我已经单独测试过了,所以我认为我实现补丁固定装置的方式有问题,但我似乎无法解决
【问题讨论】:
标签: python pytest monkeypatching