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

Allow erroring on remaining tasks after test exit as an option

Đang mở
#1,044 3 bình luận 1 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
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
python
Lĩnh vực
testing

Hướng nghiên cứu

Bắt đầu bằng cách đọc fixture được tham chiếu trong ophyd-async tests/conftest.py ở các dòng 72-137 để hiểu hành vi cleanup mong muốn. Sau đó, kiểm tra cách pytest-asyncio hiện xử lý fixture và event loop, đồng thời xác định tùy chọn có thể cấu hình nên nằm ở đâu. Công việc được xem là hoàn tất khi tùy chọn phát hiện và báo cáo các task chưa hoàn thành sau mỗi test, hủy chúng và có các test tập trung cho hành vi được bật và bị tắt.

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

Mô tả

Problem

In ophyd-async, we want a test environment where if there are unfinished tasks after any test has finished then the test will error. We had quite a lot "task destroyed but it was pending" teardown errors which would pop up in later tests, with no description of which test the task was started in.

To fix this, we made an autouse fixture which would add a finalizer to every test and raise an error if there are any tasks still running after the test finishes, and cancel the task.

https://github.com/bluesky/ophyd-async/blob/16b794a490d7cb91dd695a261133036e89f93da1/tests/conftest.py#L72-L137

This gives us a much more precise error on the exact task/test which hasn't been handled, but most importantly ensures later tests don't raise errors solely by virtue of running when the previous tests task is garbage collected:

ERROR tests/epics/adaravis/test_aravis.py::test_unsupported_trigger_excepts - RuntimeError: Not all tasks closed during test test_unsupported_trigger_excepts:
{<Task cancelling name='Task-2282' coro=<_wrap_awaitable() running at /dls_sw/apps/python/miniforge/4.10.0-0/envs/python3.11/lib/python3.11/asyncio/tasks.py:684> wait_for=<Task finished name='Task-2281' coro=<SignalW.set() done, defined at /scratch/twj43146/Programming/ophyd-async/src/ophyd_async/core/_signal.py:228> result=None created at /dls_sw/apps/python/miniforge/4.10.0-0/envs/python3.11/lib/python3.11/asyncio/tasks.py:374> cb=[gather.<locals>._done_callback() at /dls_sw/apps/python/miniforge/4.10.0-0/envs/python3.11/lib/python3.11/asyncio/tasks.py:754] created at /dls_sw/apps/python/miniforge/4.10.0-0/envs/python3.11/lib/python3.11/asyncio/tasks.py:670>}

Suggestion

I couldn't find details on options to get this behaviour in pytest out of the box, but it seems quite useful. Could something like this be a configurable option and packaged with pytest?

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.