allure-python
allure-python copied to clipboard
fix: step tree incorrect when spawn thread nestly #872
Context
Fix #872: Providing an approach to fix incorrect step tree when testing multithread(and spawned nested threads). In this approach, it's needed to explictly initialize thread for allure in new spawned thread(to propagate parent thread's state into new spawned child thread ---- any other elegant way? I have googled but not found.)
Example
adjusting example in #872:
from concurrent.futures import ThreadPoolExecutor
import allure
def session_on_node(node_id, session):
with allure.step(f"Session#{session} on Node#{node_id}"):
pass
def parallel_task_for_specific_node(node_id):
with allure.step(f"Node#{node_id}") as step:
with ThreadPoolExecutor(initializer=step.get_thread_initializer()) as executor:
for session in range(3):
executor.submit(session_on_node, node_id, session)
executor.shutdown(wait=True)
def test_multithreaded():
with allure.step("Root") as step:
with ThreadPoolExecutor(initializer=step.get_thread_initializer()) as executor:
for node_id in range(3):
executor.submit(parallel_task_for_specific_node, node_id)
executor.shutdown(wait=True)
we could get report with expected step tree:
Checklist
- [x] Sign Allure CLA
- [x] Provide unit tests