Dynamically calling async fixture causes a runtime error saying "This event loop is already running"
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
- 50/100
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện các trường hợp fixture động và cố định trong tests/test_app_factory.py, sau đó kiểm tra pytest_asyncio/plugin.py quanh wrapper ở dòng 97 và đường dẫn pytest.request.getfixturevalue được hiển thị trong traceback. Được xem là hoàn tất khi bài kiểm thử fixture async động hoàn thành mà không gặp lỗi runtime của event loop và trả về giá trị fixture mong đợi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
There seems to be a bug with how request.getfixturevalue(argname) interacts with pytest-asyncio. Calling the function leads to a runtime error saying the event loop is already running. If you change it from being dynamically called to being fixed in the function definition, it works as expected.
Platform Info:
platform win32 -- Python 3.7.2, pytest-4.2.0, py-1.7.0, pluggy-0.8.1
plugins: asyncio-0.11.0.dev0
Test fixture that can be used in both dynamic/fixed cases:
@pytest.fixture
async def async_fixture():
yield 'Hi from async_fixture()!'
Successful fixed function argument fixture test:
@pytest.mark.asyncio
async def test_async_fixture_fixed(async_fixture):
assert async_fixture == 'Hi from async_fixture()!'
Failed dynamic fixture test:
@pytest.mark.asyncio
async def test_async_fixture_dynamic(request):
async_fixture = request.getfixturevalue('async_fixture')
assert async_fixture == 'Hi from async_fixture()!'
Failed test trace-back:
================================== FAILURES ===================================
_________________________ test_async_fixture_dynamic __________________________
request = <FixtureRequest for <Function test_async_fixture_dynamic>>
@pytest.mark.asyncio
async def test_async_fixture_dynamic(request):
> async_fixture = request.getfixturevalue('async_fixture')
tests\test_app_factory.py:52:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv\lib\site-packages\_pytest\fixtures.py:478: in getfixturevalue
return self._get_active_fixturedef(argname).cached_result[0]
venv\lib\site-packages\_pytest\fixtures.py:501: in _get_active_fixturedef
self._compute_fixture_value(fixturedef)
venv\lib\site-packages\_pytest\fixtures.py:586: in _compute_fixture_value
fixturedef.execute(request=subrequest)
venv\lib\site-packages\_pytest\fixtures.py:881: in execute
return hook.pytest_fixture_setup(fixturedef=self, request=request)
venv\lib\site-packages\pluggy\hooks.py:284: in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
venv\lib\site-packages\pluggy\manager.py:68: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
venv\lib\site-packages\pluggy\manager.py:62: in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
venv\lib\site-packages\_pytest\fixtures.py:923: in pytest_fixture_setup
result = call_fixture_func(fixturefunc, request, kwargs)
venv\lib\site-packages\_pytest\fixtures.py:782: in call_fixture_func
res = fixturefunc(**kwargs)
..\pytest-asyncio\pytest_asyncio\plugin.py:97: in wrapper
return loop.run_until_complete(setup())
C:\Users\ykuzm\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py:571: in run_until_complete
self.run_forever()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_WindowsSelectorEventLoop running=False closed=False debug=False>
def run_forever(self):
"""Run until stop() is called."""
self._check_closed()
if self.is_running():
> raise RuntimeError('This event loop is already running')
E RuntimeError: This event loop is already running
- 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
- Đọ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 · 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 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ự
-
bug status/needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
prowler-cloud/prowler#12887 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: desktop platform: macos priority: p3 status: ready type: enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
use-agent-os/agent-os#3484 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
open-telemetry/opentelemetry-python-contrib#5113 · 2 bình luận · 2 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
external
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
langchain-ai/docs#6255 ·
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 72/100
Maintainer thường phản hồi trong vòng 1 ngày