"The test […] is not an async function" when `asyncio` marker is added via `pytest_collection_modifyitems()`
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- python
- Lĩnh vực
- testing-qa
Hướng nghiên cứu
Bắt đầu với reproducer trong conftest.py và test_foo.py, sau đó kiểm tra cách pytest-asyncio xử lý các marker được thêm bởi pytest_collection_modifyitems(). So sánh hành vi giữa pytest-asyncio 0.23.6 và 0.21.1. Được xem là hoàn tất khi bài kiểm thử async được nhận diện và thực thi khi marker asyncio được thêm trong quá trình collection, mà không có cảnh báo được hiển thị.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
This one I've noticed while testing IPython. The simplest reproducer is:
conftest.py:
import inspect
def pytest_collection_modifyitems(items):
for item in items:
if inspect.iscoroutinefunction(item.obj):
item.add_marker("asyncio")
test_foo.py:
async def test_foo():
pass
With pytest-asyncio 0.23.6, I'm getting:
========================================================= test session starts =========================================================
platform linux -- Python 3.11.8, pytest-8.1.1, pluggy-1.4.0
rootdir: /tmp/repro
plugins: asyncio-0.23.6
asyncio: mode=Mode.STRICT
collected 1 item
test_foo.py s [100%]
========================================================== warnings summary ===========================================================
test_foo.py::test_foo
test_foo.py:5: PytestWarning: The test <Function test_foo> is marked with '@pytest.mark.asyncio' but it is not an async function. Please remove the asyncio mark. If the test is not marked explicitly, check for global marks applied via 'pytestmark'.
async def test_foo():
test_foo.py::test_foo
/tmp/repro/.venv/lib/python3.11/site-packages/_pytest/python.py:184: PytestUnhandledCoroutineWarning: async def functions are not natively supported and have been skipped.
You need to install a suitable plugin for your async framework, for example:
- anyio
- pytest-asyncio
- pytest-tornasync
- pytest-trio
- pytest-twisted
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(nodeid)))
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================== 1 skipped, 2 warnings in 0.01s ====================================================
With pytest-asyncio-0.21.1, the test is correctly run as marked.
- Ngôn ngữ chính
- Python
- Star
- 1.7k
- Fork
- 207
- Merge trung bình
- 5 giờ 2 phút
- Pull request đã merge (30 ngày)
- 11
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
- Đọ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.
Issue khác của pytest-dev/pytest-asyncio
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
pytest-dev/pytest-asyncio#1475 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 56/100
pytest-dev/pytest-asyncio#1514 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
pytest-dev/pytest-asyncio#1501 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
pytest-dev/pytest-asyncio#1463 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Don't warn about `asyncio_default_fixture_loop_scope` unless the test suite uses `pytest-asyncio`Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
pytest-dev/pytest-asyncio#1344 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của pytest-dev/pytest-asyncio
Issue tương tự
-
ACK_WAITING HELP_WANTED UPDATE_CS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OWASP/CheatSheetSeries#2458 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
BasedHardware/omi#19711 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Qwen3_5MoeModel no longer returns router_logits, breaking aux loss with output_router_logits=TrueĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
huggingface/transformers#49172 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
vllm-project/vllm-metal#885 ·
Maintainer thường phản hồi trong vòng 1 ngày