Skip to content

Commit 7e6e700

Browse files
authored
Add group to the test context (#14440)
1 parent 82ccb94 commit 7e6e700

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Diff for: lib/ex_unit/lib/ex_unit/case.ex

+2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ defmodule ExUnit.Case do
163163
164164
* `:test` - the test name
165165
166+
* `:test_group` - the group the test belongs to
167+
166168
* `:test_pid` - the PID of the testing process
167169
168170
* `:test_type` - the test type used when printing test results.

Diff for: lib/ex_unit/lib/ex_unit/runner.ex

+13-6
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ defmodule ExUnit.Runner do
165165
running
166166
end
167167

168-
defp spawn_modules(config, [{_group, [_ | _] = modules} | groups], async?, running) do
168+
defp spawn_modules(config, [{group, [_ | _] = modules} | groups], async?, running) do
169169
if max_failures_reached?(config) do
170170
running
171171
else
172172
{pid, ref} =
173173
spawn_monitor(fn ->
174174
Enum.each(modules, fn {module, params} ->
175-
run_module(config, module, async?, params)
175+
run_module(config, module, async?, group, params)
176176
end)
177177
end)
178178

@@ -231,12 +231,13 @@ defmodule ExUnit.Runner do
231231

232232
## Running modules
233233

234-
defp run_module(config, module, async?, params) do
234+
defp run_module(config, module, async?, group, params) do
235235
test_module = %{module.__ex_unit__() | parameters: params}
236236
EM.module_started(config.manager, test_module)
237237

238238
# Prepare tests, selecting which ones should be run or skipped
239-
{to_run_tests, excluded_and_skipped_tests} = prepare_tests(config, async?, test_module.tests)
239+
{to_run_tests, excluded_and_skipped_tests} =
240+
prepare_tests(config, async?, group, test_module.tests)
240241

241242
for excluded_or_skipped_test <- excluded_and_skipped_tests do
242243
EM.test_started(config.manager, excluded_or_skipped_test)
@@ -271,7 +272,7 @@ defmodule ExUnit.Runner do
271272
end
272273
end
273274

274-
defp prepare_tests(config, async?, tests) do
275+
defp prepare_tests(config, async?, group, tests) do
275276
tests = shuffle(config, tests)
276277
include = config.include
277278
exclude = config.exclude
@@ -280,7 +281,13 @@ defmodule ExUnit.Runner do
280281
{to_run, to_skip} =
281282
for test <- tests, include_test?(test_ids, test), reduce: {[], []} do
282283
{to_run, to_skip} ->
283-
tags = Map.merge(test.tags, %{test: test.name, module: test.module, async: async?})
284+
tags =
285+
Map.merge(test.tags, %{
286+
test: test.name,
287+
module: test.module,
288+
async: async?,
289+
test_group: group
290+
})
284291

285292
case ExUnit.Filters.eval(include, exclude, tags, tests) do
286293
:ok -> {[%{test | tags: tags} | to_run], to_skip}

Diff for: lib/ex_unit/test/ex_unit/case_test.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Code.require_file("../test_helper.exs", __DIR__)
66

77
defmodule ExUnit.CaseTest do
8-
use ExUnit.Case, async: true
8+
use ExUnit.Case, async: true, group: :group_foo
99

1010
ExUnit.Case.register_attribute(__MODULE__, :foo)
1111
ExUnit.Case.register_attribute(__MODULE__, :bar, accumulate: true)
@@ -40,6 +40,7 @@ defmodule ExUnit.CaseTest do
4040
assert context[:test_type] == :test
4141
assert context[:hello] == true
4242
assert context[:world] == :good
43+
assert context[:test_group] == :group_foo
4344
end
4445

4546
test "reset tags", context do

0 commit comments

Comments
 (0)