new_callable arg to unittest.mock.patch seems not to support partial
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
As in the title. The following code seems to disregard the partial and proceed to call the wrapped function right away (instead of calling the wrapping partial object).
from functools import partial
from unittest.mock import patch
def wrapped():
"""an exemplary response from `some.directory.module.my_function` function"""
return [
{
"some_key": "some_value",
}]
def test_some_func():
with patch(
"some.directory.module.my_function", new_callable=partial(wrapped)
):
# calls `my_function` internally
some.directory.module.another_function()
Running the above will produce: TypeError: 'list' object is not callable.
Acc. to the docs an object passed as new_callable argument should be called by patch to create a new dummy object replacing the target (some.directory.module.my_function). However it seems that instead of partial being called and returning a wrapped function, a wrapped function itself is called returning the list.
CPython versions tested on:
3.11
Operating systems tested on:
macOS
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với entry point unittest.mock.patch và cách xử lý new_callable của nó, sử dụng reproducer partial(wrapped) trong báo cáo. So sánh chuỗi lời gọi quan sát được với contract đã được tài liệu hóa, sau đó thêm hoặc cập nhật coverage hồi quy để target được thay thế bằng hành vi callable như mong đợi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- testing
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100