Uploaded image for project: 'Erlang/OTP'
  1. Erlang/OTP
  2. ERL-591

EUnit test generators run twice

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Not a Bug
    • Affects Version/s: 20.2
    • Fix Version/s: None
    • Component/s: eunit
    • Labels:
      None

      Description

      Given the following test module:

      -module(my_test).
      
      -include_lib("eunit/include/eunit.hrl").
      
      a_test_() ->
          io:format(user, "IN A GENERATOR 1~n", []),
          [fun() -> io:format(user, "IN A TEST 1~n", []) end].
      
      b_test_() ->
          io:format(user, "IN A GENERATOR 2~n", []),
          [fun() -> io:format(user, "IN A TEST 2~n", []) end].
      

      Running it yields:

      1> eunit:test(my_test).
      IN A GENERATOR 1
      IN A GENERATOR 2
      IN A GENERATOR 1
      IN A TEST 1
      IN A GENERATOR 2
      IN A TEST 2
        2 tests passed.
      ok
      

      This means the generators are run twice, but the test cases only run once (as they should).

      The expected outcome would be for generators not to run twice, since they usually contain heavy setup work or could contain mutable state that gets corrupted if run several times.

        Attachments

          Activity

            People

            Assignee:
            hasse Hans Bolinder
            Reporter:
            eproxus Adam Lindberg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: