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 于 46 天前认领。 未关闭
难度 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 于 51 天前认领。 未关闭
难度 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
-
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 82/100
fabriziosalmi/certmate#1207 ·
维护者通常 1 天内回复
-
[work-item] adam-adae-onset-emergence: document the minute-precision datetime coercion (ASTTMF not derivable)可能已有人在做 @muse-yamaa-bot 今天认领。 未关闭work-item
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
CommunityToolkit/Aspire#2231 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
volcengine/OpenViking#5711 ·
维护者通常 1 天内回复