Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

TaskGroup around yield in fixture doesn't terminate with exceptions

Đang mở
#1,083 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/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-qa

Hướng nghiên cứu

Bắt đầu với fixture và test tối thiểu trong tests/conftest.py từ ví dụ được liên kết, sau đó chạy chúng để tái hiện hiện tượng treo. Đọc công thức kết thúc của asyncio TaskGroup và theo dõi cách pytest-asyncio xử lý teardown của fixture async-generator. Hoàn thành khi exception bị trì hoãn hủy task còn lại và khiến fixture hoặc test thất bại thay vì treo vô thời hạn.

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

Mô tả

I tried to make a fixture to throw an exception after a certain amount of time to catch deadlocks in my tests, but the exception isn't causing the TaskGroup to error out.

Here is a minimal example fixture that interacts with a literally trivial test
https://github.com/sawalls/pytest-asyncio-example/blob/main/tests/conftest.py

@fixture(scope="function")
async def async_buddy():
    mytasks = set()
    async def forever_loop():
        while True:
            await sleep(1)

    async def exception_task():
        await sleep(5)
        raise Exception("This is an exception")

    async with TaskGroup() as tg:
        mytasks.add(tg.create_task(forever_loop()))
        mytasks.add(tg.create_task(exception_task()))
        yield

---

async def test_example(async_buddy):
    pass

It's inspired by the recipe in the python docs to terminate a TaskGroup:
https://docs.python.org/3/library/asyncio-task.html#terminating-a-task-group

Expected behavior:

  1. Make TaskGroup
  2. Make Tasks
  3. Yield to test, which returns immediately
  4. Enter context manager waiting for tasks
  5. Get Exception from exception task, cancel all tasks, and throw out of the fixture

Observed behavior:

  1. Make TaskGroup
  2. Make Tasks
  3. Yield to test, which returns immediately (so at this point the test has reported success)
  4. Enter context manager waiting for tasks
  5. Hangs indefinitely

Please let me know if there's anything about my intentions I can make more clear or documents I should read to get a better understanding.

Also, if you want to direct me at some code to understand the library's understanding of this, I may be able to try and reason about it.

Ngôn ngữ chính
Python
Star
1.7k
Fork
207
Merge trung bình
4 giờ 38 phút
Pull request đã merge (30 ngày)
12

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

Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 pytest-dev/pytest-asyncio

Tất cả issue của pytest-dev/pytest-asyncio

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.