allure-pytest raises an exception when writing to log from a thread started inside pytest_generate_tests
還沒有人認領這個 Issue。
評估
研究方向
使用 conftest.py 和 test_bug.py 範例重現此失敗,從 pytest_generate_tests 和執行緒化記錄處理常式開始。追蹤回溯中顯示的 Allure 步驟建立過程,並驗證執行緒內容的行為。當範例使用 pytest -s --alluredir=./allure 執行且未發生 StopIteration 例外時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
I'm submitting a ...
- bug report
What is the current behavior?
I have a function that creates a thread which writes some information in the log. When I try to call it from pytest_generate_tests allure-pytest raises the following StopIteration exception:
platform linux -- Python 3.9.16, pytest-7.4.0, pluggy-1.2.0
rootdir: /mnt/c/storage/allure_bug
plugins: allure-pytest-2.13.2
collecting ... Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 980, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 917, in run
self._target(*self._args, **self._kwargs)
File "/mnt/c/storage/allure_bug/conftest.py", line 17, in _thread
log.warning('thread')
File "/usr/lib/python3.9/logging/init.py", line 1458, in warning
self._log(WARNING, msg, args, **kwargs)
File "/usr/lib/python3.9/logging/init.py", line 1589, in _log
self.handle(record)
File "/usr/lib/python3.9/logging/init.py", line 1599, in handle
self.callHandlers(record)
File "/usr/lib/python3.9/logging/init.py", line 1661, in callHandlers
hdlr.handle(record)
File "/usr/lib/python3.9/logging/init.py", line 952, in handle
self.emit(record)
File "/mnt/c/storage/allure_bug/conftest.py", line 9, in emit
with step(f'[{record.levelname}] {record.getMessage()}'):
File "/tmp/test_venv/lib/python3.9/site-packages/allure_commons/_allure.py", line 179, in enter
plugin_manager.hook.start_step(uuid=self.uuid, title=self.title, params=self.params)
File "/tmp/test_venv/lib/python3.9/site-packages/pluggy/_hooks.py", line 433, in call
return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
File "/tmp/test_venv/lib/python3.9/site-packages/pluggy/_manager.py", line 112, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/tmp/test_venv/lib/python3.9/site-packages/pluggy/_callers.py", line 116, in _multicall
raise exception.with_traceback(exception.traceback)
File "/tmp/test_venv/lib/python3.9/site-packages/pluggy/_callers.py", line 80, in _multicall
res = hook_impl.function(*args)
File "/tmp/test_venv/lib/python3.9/site-packages/allure_pytest/listener.py", line 48, in start_step
self.allure_logger.start_step(None, uuid, step)
File "/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py", line 128, in start_step
parent_uuid = parent_uuid if parent_uuid else self._last_executable()
File "/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py", line 71, in _last_executable
for _uuid in reversed(self._items):
File "/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py", line 39, in reversed
return self.thread_context.reversed()
File "/tmp/test_venv/lib/python3.9/site-packages/allure_commons/reporter.py", line 21, in thread_context
uuid, last_item = next(reversed(self._thread_context[self._init_thread].items()))
StopIteration
collected 1 item
test_bug.py test
.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
- Install requirements
pip install pytest allure-pytest - Prepare the demo test suite:
conftest.py
import logging
from threading import Thread
from allure import step
class AllureLoggerHandler(logging.Handler):
def emit(self, record):
with step(f'[{record.levelname}] {record.getMessage()}'):
pass
log = logging.getLogger()
allure_handler = AllureLoggerHandler()
log.addHandler(allure_handler)
def _thread():
log.warning('thread')
def pytest_generate_tests(metafunc):
log.info('generate')
thread = Thread(target=_thread)
thread.start()
thread.join(100)
test_bug.py
def test_allure_log():
print('test')
- Run test:
pytest -s --alluredir=./allure
What is the expected behavior?
Test suite works without any exceptions
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
- Allure version: 2.22.0
- Test framework: pytest 7.4.0
- Allure adaptor: allure-pytest 2.13.2
Other information
- 主要語言
- Python
- 星號
- 819
- 分支
- 261
- 平均合併
- 3 小時 20 分鐘
- 30 天內合併 PR
- 3
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
allure-framework/allure-python 的其他 Issue
-
[allure-behave] Steps from tag-excluded scenarios bleed into the next matching scenario's result when hide_excluded=true可能已有人在做 @liuyaohui666 於 48 天前認領。 未關閉
難度 1/5 1 小時以內 新手友好度 84/100
-
theme:pytest
難度 3/5 1-2 天 新手友好度 64/100
allure-framework/allure-python#929 · 1 個 reaction ·
-
Added Categories未關閉
難度 3/5 1-2 天 新手友好度 55/100
-
Phantom <lambda> teardown entries with unknown status when using pytest 9.1+可能已有人在做 @Mohanad49 於 53 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 58/100
allure-framework/allure-python#918 · 1 個 reaction ·
-
難度 4/5 3-5 天 新手友好度 45/100
allure-framework/allure-python#903 · 1 則留言 ·
查看 allure-framework/allure-python 的全部 Issue
相似的 Issue
-
first
難度 2/5 1-3 小時 新手友好度 72/100
AcademySoftwareFoundation/rmtc#54 · 1 則留言 ·
-
feature/cohorts feature/feature-flags team/feature-flags
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
License examples/ as MIT可能已有人在做 @PGrayCS 今天認領。 未關閉documentation enhancement example good first issue
難度 2/5 1-3 小時 新手友好度 84/100
speedyk-005/yasbd-lib#383 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
interactions-py/interactions.py#1827 ·
-
Managed start can fail when OpenVMM reads its control capability before NVX writes it可能已有人在做 @ppenna 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆