Skip to content

Conversation

SalHe
Copy link

@SalHe SalHe commented Aug 9, 2025

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:

image

Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Step tree seems not correct in multithreaded testing
1 participant