unittest.mock: Double period in AttributeError message for invalid assertion methods
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:
When accessing a non-existent assertion method on a [Mock] object( e.g., assert_called_twice_with), the raised [AttributeError] message contains a double period (..) before the "Did you mean" suggestion.
Example
import unittest.mock as mock
m = mock.Mock()
m.assert_called_twice_with(1, 2)
Output
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.12/unittest/mock.py", line 665, in __getattr__
raise AttributeError(
AttributeError: 'assert_called_twice_with' is not a valid assertion. Use a spec for the mock if 'assert_called_twice_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?
Problem
Note the double period ([attribute.. Did you mean] in the error message.
Expected Behavior
The error message should contain only a single period before the suggestion, e.g.:
Expected Output
AttributeError: 'assert_called_twice_with' is not a valid assertion. Use a spec for the mock if 'assert_called_twice_with' is meant to be an attribute. Did you mean: 'assert_called_once_with'?
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PR
Linked PRs
- gh-137717
- gh-138111
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 trong unittest/mock.py tại Mock.getattr, điểm vào được hiển thị trong traceback. Kiểm tra các bài kiểm thử unittest.mock hiện có cho các phương thức assertion không hợp lệ và điều chỉnh thông báo để gợi ý theo sau một dấu chấm duy nhất; các bài kiểm thử liên quan phải xác nhận nội dung AttributeError đã được sửa.
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-qa
- Loại issue
- Lỗi
- Độ khó
- 1/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 25/100