From 3c51dee2bd9a54476ff1a52e235a97b2ab15bbb2 Mon Sep 17 00:00:00 2001 From: Isaac Yonemoto Date: Sat, 5 Oct 2024 17:06:25 -0500 Subject: [PATCH 1/2] adds test_pid field in the test metdata --- lib/ex_unit/lib/ex_unit.ex | 2 ++ lib/ex_unit/lib/ex_unit/runner.ex | 1 + 2 files changed, 3 insertions(+) diff --git a/lib/ex_unit/lib/ex_unit.ex b/lib/ex_unit/lib/ex_unit.ex index 4c60a495cb2..c7e872ba2b7 100644 --- a/lib/ex_unit/lib/ex_unit.ex +++ b/lib/ex_unit/lib/ex_unit.ex @@ -103,6 +103,8 @@ defmodule ExUnit do * `:logs` - the captured logs * `:parameters` - the test parameters + When a test has finished, the following fields are added for consumption by `ExUnit.Formatter` callbacks: + * `:test_pid` - the pid that the test was running on """ defstruct [:name, :case, :module, :state, time: 0, tags: %{}, logs: "", parameters: %{}] diff --git a/lib/ex_unit/lib/ex_unit/runner.ex b/lib/ex_unit/lib/ex_unit/runner.ex index 29bd90d3716..4adda30588a 100644 --- a/lib/ex_unit/lib/ex_unit/runner.ex +++ b/lib/ex_unit/lib/ex_unit/runner.ex @@ -456,6 +456,7 @@ defmodule ExUnit.Runner do end defp receive_test_reply(test, test_pid, test_ref, timeout) do + test = Map.put(test, :test_pid, test_pid) receive do {^test_pid, :test_finished, test} -> Process.demonitor(test_ref, [:flush]) From 5f405b5ea93c76379ff9a2fc69ab7af07984fb7f Mon Sep 17 00:00:00 2001 From: Isaac Yonemoto Date: Sun, 6 Oct 2024 10:18:01 -0500 Subject: [PATCH 2/2] Update lib/ex_unit/lib/ex_unit.ex Co-authored-by: Andrea Leopardi --- lib/ex_unit/lib/ex_unit.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ex_unit/lib/ex_unit.ex b/lib/ex_unit/lib/ex_unit.ex index c7e872ba2b7..fbe3b40eb22 100644 --- a/lib/ex_unit/lib/ex_unit.ex +++ b/lib/ex_unit/lib/ex_unit.ex @@ -104,7 +104,7 @@ defmodule ExUnit do * `:parameters` - the test parameters When a test has finished, the following fields are added for consumption by `ExUnit.Formatter` callbacks: - * `:test_pid` - the pid that the test was running on + * `:test_pid` - the PID that the test was running on """ defstruct [:name, :case, :module, :state, time: 0, tags: %{}, logs: "", parameters: %{}]