Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ex_unit/lib/ex_unit/case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 13 additions & 6 deletions lib/ex_unit/lib/ex_unit/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion lib/ex_unit/test/ex_unit/case_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading