test_stream_timeout and test_urllib3_pool_connection_closed pass without asserting when no exception is raised

Đang mở Phù hợp với người mới
#7,639 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
testing

Hướng nghiên cứu

Bắt đầu từ tests/test_requests.py, tại TestTimeout.test_stream_timeout và test_invalid_timeout ở gần đó, hàm này đã dùng pytest.raises. Chạy các test timeout với fixture httpbin để xác nhận chúng đang pass. Sau đó kiểm tra test_urllib3_pool_connection_closed, nơi assertion nằm trong khối except. Hoàn thành khi mỗi test đều fail nếu exception mong đợi không được raise. Test thứ hai có thể cần maintainer quyết định nên assert hành vi nào.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Two tests in tests/test_requests.py put their only assertion inside an except block, so they pass without checking anything when the exception is not raised.

TestTimeout.test_stream_timeout: if the request to delay/10 completed without timing out, the test would pass. Switching it to pytest.raises (like test_invalid_timeout right below it) makes it fail in that case:

def test_stream_timeout(self, httpbin):
    with pytest.raises(requests.exceptions.Timeout) as e:
        requests.get(httpbin("delay/10"), timeout=2.0)
    assert "Read timed out" in e.value.args[0].args[0]

I checked that this version passes as is and fails with DID NOT RAISE when pointed at delay/0. The change is in this commit on my fork, if it's useful: https://github.com/jeffev/requests/commit/b5058def5811

test_urllib3_pool_connection_closed: with the current urllib3, s.get() on an adapter mounted with pool_connections=0, pool_maxsize=0 succeeds (I get a 200), so the except ConnectionError branch never runs and the test checks nothing. I'm not sure what behavior it should pin down now, so I didn't touch it.

I'd have opened a PR, but pull requests seem limited to collaborators.

Ngôn ngữ chính
Python
Star
54.6k
Fork
12.1k
Merge trung bình
18 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của psf/requests

Tất cả issue của psf/requests

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.