Skip to content

Commit 8ed104d

Browse files
committed
Add test_pid tag to ExUnit.Case
Closes #13880.
1 parent f44aa8d commit 8ed104d

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lib/ex_unit/lib/ex_unit/case.ex

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,30 +147,32 @@ defmodule ExUnit.Case do
147147
The following tags are set automatically by ExUnit and are
148148
therefore reserved:
149149
150-
* `:module` - the module on which the test was defined
150+
* `:async` - if the test case is in async mode
151151
152152
* `:file` - the file on which the test was defined
153153
154154
* `:line` - the line on which the test was defined
155155
156+
* `:module` - the module on which the test was defined
157+
158+
* `:registered` - used for `ExUnit.Case.register_attribute/3` values
159+
156160
* `:test` - the test name
157161
158-
* `:async` - if the test case is in async mode
162+
* `:test_pid` - the PID of the testing process
159163
160-
* `:registered` - used for `ExUnit.Case.register_attribute/3` values
164+
* `:test_type` - the test type used when printing test results.
165+
It is set by ExUnit to `:test`, `:doctest` and so on, but is customizable.
161166
162-
* `:describe` - the describe block the test belongs to
167+
* `:describe` - the describe block the test belongs to (if in a describe)
163168
164-
* `:describe_line` - the line the describe block begins on
169+
* `:describe_line` - the line the describe block begins on (if in a describe)
165170
166171
* `:doctest` - the module or the file being doctested (if a doctest)
167172
168-
* `:doctest_line` - the line the doctest was defined (if a doctest)
169-
170173
* `:doctest_data` - additional metadata about doctests (if a doctest)
171174
172-
* `:test_type` - the test type used when printing test results.
173-
It is set by ExUnit to `:test`, `:doctest` and so on, but is customizable.
175+
* `:doctest_line` - the line the doctest was defined (if a doctest)
174176
175177
The following tags customize how tests behave:
176178

lib/ex_unit/lib/ex_unit/runner.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ defmodule ExUnit.Runner do
426426
spawn_monitor(fn ->
427427
ExUnit.OnExitHandler.register(self())
428428
generate_test_seed(seed, test, rand_algorithm)
429-
context = Map.merge(context, test.tags)
429+
context = context |> Map.merge(test.tags) |> Map.put(:test_pid, self())
430430
capture_log = Map.get(context, :capture_log, capture_log)
431431

432432
{time, test} =

lib/ex_unit/test/ex_unit/case_test.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ defmodule ExUnit.CaseTest do
2828
@tag world: :good
2929
test "tags", context do
3030
line = __ENV__.line - 1
31+
assert context[:async] == true
32+
assert context[:line] == line
3133
assert context[:module] == __MODULE__
3234
assert context[:test] == __ENV__.function |> elem(0)
33-
assert context[:line] == line
34-
assert context[:async] == true
35+
assert context[:test_pid] == self()
36+
assert context[:test_type] == :test
3537
assert context[:hello] == true
3638
assert context[:world] == :good
3739
end

0 commit comments

Comments
 (0)