elixir-lang / elixir

Elixir is a dynamic, functional language for building scalable and maintainable applications
https://elixir-lang.org/
Apache License 2.0
24.3k stars 3.35k forks source link

Include test times when sending `:module_finished` event to ExUnit formatters #8112

Closed devonestes closed 6 years ago

devonestes commented 6 years ago

Environment

Elixir 1.7.1 (compiled with Erlang/OTP 19)

Current behavior

When writing a custom formatter, the %ExUnit.TestModule{} struct that is sent as part of the :module_finished cast includes all of the tests in that module, but it does not include the correct run times of those tests. For example, in that message I get:

%ExUnit.TestModule{
  name: TestmetricsElixirClientTest.BasicTest,
  state: nil,
  tests: [
    %ExUnit.Test{
      case: TestmetricsElixirClientTest.BasicTest,
      logs: "",
      module: TestmetricsElixirClientTest.BasicTest,
      name: :"test false",
      state: nil,
      tags: %{
        async: true,
        describe: nil,
        describe_line: nil,
        file: "/Users/devoncestes/sandbox/testmetrics/testmetrics_elixir_client/test/testmetrics_elixir_client_test.exs",
        line: 13,
        registered: %{},
        test_type: :test
      },
      time: 0
    },
    %ExUnit.Test{
      case: TestmetricsElixirClientTest.BasicTest,
      logs: "",
      module: TestmetricsElixirClientTest.BasicTest,
      name: :"test true",
      state: nil,
      tags: %{
        async: true,
        describe: nil,
        describe_line: nil,
        file: "/Users/devoncestes/sandbox/testmetrics/testmetrics_elixir_client/test/testmetrics_elixir_client_test.exs",
        line: 9,
        registered: %{},
        test_type: :test
      },
      time: 0
    }
  ]
}

Expected behavior

I would expect that the :time for each test in the test module would be updated to reflect how long the test actually took to run. Essentially, I would expect that the :tests key would be updated to include the new structs that are sent as part of the :test_finished message, so they include the run times of each test and an updated :state of each test, including failure information for failed tests.

josevalim commented 6 years ago

@devonestes good catch. Can you please investigate how hard would be to fix this? I think we should be able to return the test results before calling module finished. Thanks!