Skip to content

fix: step tree incorrect when spawn thread nestly #872 #874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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