python - Pytests:获取错误函数不使用参数错误
问题描述
我有以下代码
@pytest.fixture
def mock_path_functions(mocker, file_exists=True, file_size=10):
mock_obj = mock.Mock()
mock_obj.st_size = file_size
mocker.patch("os.path.exists", return_value=file_exists)
mocker.patch("os.stat", return_value=mock_obj)
@pytest.mark.usefixtures("mock_path_functions")
@ytest.mark.parametrize("file_exists,file_size", [(False, 0)])
def test_subscrition_handle_from_file_when_file_is_not_present():
assert subscrition_handle_from_file("some path") == None
但是我收到以下错误:
In test_subscrition_handle_from_file_when_file_is_not_present: function uses no argument 'file_exists'
如何为 mock_path_function 指定参数?
解决方案
我认为您只需要将参数传递给您的测试函数,例如
@pytest.mark.usefixtures("mock_path_functions")
@ytest.mark.parametrize("file_exists,file_size", [(False, 0)])
def test_subscrition_handle_from_file_when_file_is_not_present(
file_exists, file_size
):
assert subscrition_handle_from_file("some path") == None
推荐阅读
- ios - NavigationLink 没有将新视图拉到正确的位置
- javascript - MERN router.get 请求返回未定义
- python - 在python中只选择ID的最新记录
- android - 如何使用 Jetpack Compose 垂直堆叠文本并旋转?
- python-3.x - 我怎样才能使这种“基于类的视图”起作用?
- sqlite - 如何在python中选择名称中带有句点的SQLite表
- instagram - 如何在instagram中显示图片数量
- swift - 如何使用索引访问惰性序列?
- html - 为什么我的网格元素之间有这么大的“间隙”,而grid-gap = 0?
- javascript - 在 javascript 中让 setTimeout() 函数运行?