【发布时间】:2021-09-15 13:31:44
【问题描述】:
我开发了一个包含许多功能的程序。我现在正在测试这些功能。为此,我需要使用猴子路径方法,因为测试的函数调用输入。
因为要测试函数我需要获取之前测试的数据,用monkeypath函数我发现了困难。
data_to_test_1 = test_load_sample() # I take the data from the previous test here
# SECOND TEST
def test_take_sample(monkeypatch):
'''
take_sample() requests the name of the column
and take that input to split the data in new columns
This can be tested by checking some ofthe first values of that
columns (GT:AD:DP:GQ:PL)
monkeypatch simulate the input of the user
'''
monkeypatch.setattr('builtins.input', lambda _: "373978487") # The 9th sample in the file
data_to_test_2 = take_sample(data_to_test_1,NAME_FILE_1)
return data_to_test_2
assert data_to_test_2["GT"] == "0/1" # What I test
assert data_to_test_2["AD"] == "28,46"
assert data_to_test_2["DP"] == "74:99"
# Now, I want the output of the test_take_sample()
data_to_test_3 = test_take_sample()
def test_filter_1():
... # this function will use data_to_test_3
我在之前的函数中采用了相同的方法将数据从一个测试连接到下一个测试,但这涉及到我得到的猴子路径
test_take_sample() missing 1 required positional argument: 'monkeypatch'
【问题讨论】:
标签: python pytest monkeypatching