diff --git a/lib/ex_unit/lib/ex_unit/case.ex b/lib/ex_unit/lib/ex_unit/case.ex index 8ba4d638528..227f0ab3ecb 100644 --- a/lib/ex_unit/lib/ex_unit/case.ex +++ b/lib/ex_unit/lib/ex_unit/case.ex @@ -163,6 +163,8 @@ defmodule ExUnit.Case do * `:test` - the test name + * `:test_group` - the group the test belongs to + * `:test_pid` - the PID of the testing process * `:test_type` - the test type used when printing test results. diff --git a/lib/ex_unit/lib/ex_unit/runner.ex b/lib/ex_unit/lib/ex_unit/runner.ex index a664731da03..ff4c3b218fc 100644 --- a/lib/ex_unit/lib/ex_unit/runner.ex +++ b/lib/ex_unit/lib/ex_unit/runner.ex @@ -165,14 +165,14 @@ defmodule ExUnit.Runner do running end - defp spawn_modules(config, [{_group, [_ | _] = modules} | groups], async?, running) do + defp spawn_modules(config, [{group, [_ | _] = modules} | groups], async?, running) do if max_failures_reached?(config) do running else {pid, ref} = spawn_monitor(fn -> Enum.each(modules, fn {module, params} -> - run_module(config, module, async?, params) + run_module(config, module, async?, group, params) end) end) @@ -231,12 +231,13 @@ defmodule ExUnit.Runner do ## Running modules - defp run_module(config, module, async?, params) do + defp run_module(config, module, async?, group, params) do test_module = %{module.__ex_unit__() | parameters: params} EM.module_started(config.manager, test_module) # Prepare tests, selecting which ones should be run or skipped - {to_run_tests, excluded_and_skipped_tests} = prepare_tests(config, async?, test_module.tests) + {to_run_tests, excluded_and_skipped_tests} = + prepare_tests(config, async?, group, test_module.tests) for excluded_or_skipped_test <- excluded_and_skipped_tests do EM.test_started(config.manager, excluded_or_skipped_test) @@ -271,7 +272,7 @@ defmodule ExUnit.Runner do end end - defp prepare_tests(config, async?, tests) do + defp prepare_tests(config, async?, group, tests) do tests = shuffle(config, tests) include = config.include exclude = config.exclude @@ -280,7 +281,13 @@ defmodule ExUnit.Runner do {to_run, to_skip} = for test <- tests, include_test?(test_ids, test), reduce: {[], []} do {to_run, to_skip} -> - tags = Map.merge(test.tags, %{test: test.name, module: test.module, async: async?}) + tags = + Map.merge(test.tags, %{ + test: test.name, + module: test.module, + async: async?, + test_group: group + }) case ExUnit.Filters.eval(include, exclude, tags, tests) do :ok -> {[%{test | tags: tags} | to_run], to_skip} diff --git a/lib/ex_unit/test/ex_unit/case_test.exs b/lib/ex_unit/test/ex_unit/case_test.exs index 52c26ecc9f7..014e55d1793 100644 --- a/lib/ex_unit/test/ex_unit/case_test.exs +++ b/lib/ex_unit/test/ex_unit/case_test.exs @@ -5,7 +5,7 @@ Code.require_file("../test_helper.exs", __DIR__) defmodule ExUnit.CaseTest do - use ExUnit.Case, async: true + use ExUnit.Case, async: true, group: :group_foo ExUnit.Case.register_attribute(__MODULE__, :foo) ExUnit.Case.register_attribute(__MODULE__, :bar, accumulate: true) @@ -40,6 +40,7 @@ defmodule ExUnit.CaseTest do assert context[:test_type] == :test assert context[:hello] == true assert context[:world] == :good + assert context[:test_group] == :group_foo end test "reset tags", context do