From b091441199dd598a26cef73c526778bc9efc60e5 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Tue, 10 Jun 2025 14:59:08 +0200 Subject: [PATCH] Fix failures report when test is marked as thread-unsafe --- src/pytest_run_parallel/plugin.py | 2 +- tests/test_run_parallel.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/pytest_run_parallel/plugin.py b/src/pytest_run_parallel/plugin.py index b931cbd..206b5a9 100644 --- a/src/pytest_run_parallel/plugin.py +++ b/src/pytest_run_parallel/plugin.py @@ -249,7 +249,7 @@ def pytest_report_teststatus(report, config): ) if report.outcome == "failed": return ( - "passed", + "failed", "x", f"FAILED ([thread-unsafe]: {props['thread_unsafe_reason']})", ) diff --git a/tests/test_run_parallel.py b/tests/test_run_parallel.py index 0d52874..d8c16cd 100644 --- a/tests/test_run_parallel.py +++ b/tests/test_run_parallel.py @@ -1084,3 +1084,24 @@ def test_function_recurse_on_assign(num_parallel_threads): "*::test_function_recurse_on_assign PASSED*", ] ) + + +def test_failed_thread_unsafe(pytester): + pytester.makepyfile(""" + import pytest + + @pytest.mark.thread_unsafe + def test1(): + assert False + """) + + result = pytester.runpytest("--parallel-threads=10", "-v") + assert result.ret == 1 + print(result.stdout) + result.stdout.fnmatch_lines( + [ + "*::test1 FAILED *thread-unsafe*: uses thread_unsafe marker*", + "* FAILURES *", + "*1 failed*", + ] + )