allure-pytest raises an exception when writing to log from a thread started inside pytest_generate_tests
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
- 35/100
Hướng nghiên cứu
Tái hiện lỗi bằng các ví dụ conftest.py và test_bug.py, bắt đầu từ pytest_generate_tests và trình xử lý logging theo luồng. Theo dõi việc tạo bước Allure được hiển thị trong traceback và xác minh hành vi của ngữ cảnh luồng. Được xem là hoàn tất khi ví dụ chạy bằng pytest -s --alluredir=./allure mà không phát sinh ngoại lệ StopIteration.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 819
- Fork
- 261
- Merge trung bình
- 3 giờ 20 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
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 allure-framework/allure-python
-
[allure-behave] Steps from tag-excluded scenarios bleed into the next matching scenario's result when hide_excluded=trueCó thể đã có người làm @liuyaohui666 đã nhận 46 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
-
Added CategoriesĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
-
Phantom <lambda> teardown entries with unknown status when using pytest 9.1+Có thể đã có người làm @Mohanad49 đã nhận 51 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
allure-framework/allure-python#918 · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
allure-framework/allure-python#903 · 1 bình luận ·
-
Allure step placeholder fails when accessing dataclass attribute `data.name`Có thể đã có người làm @golikovichev đã nhận 156 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
Tất cả issue của allure-framework/allure-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Negation with "not" and "no" is ignored during sentiment analysisCó thể đã có người làm @vivek-3728 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
techcsispit/mess-mood#11 · 1 bình luận ·
-
changelog investigate
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ramnes/notion-sdk-py#408 ·
-
good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
btclib-org/btclib-wallet#267 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue tech-debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
knnmelprop/YAADO#111 ·