[erlang-bugs] Eunit, test generators and code:purge()

Magnus Henoch <>
Thu May 30 12:30:28 CEST 2013

Andrew Thompson <> writes:

> So, I've been chasing a failure in a test suite for the last couple
> days. Turns out, the problem is the test suite does this:
> * Test module A, with a test generator function
> * Test module B, and meck module A
> Eunit's runner is holding a reference to something in module A (probably
> a fun), so when meck does a purge on A as part of test B, the code
> server kills the eunit test runner process. This bug was actually
> reported three years ago:
> http://erlang.org/pipermail/erlang-bugs/2010-June/001844.html
> But it still affects at least R15B03, which is what I'm using.
> I have a slightly modified version of b_mod that proves that eunit is
> holding a ref to something from a_mod:
> -module(b_mod).
> -include_lib("eunit/include/eunit.hrl").
> second_test() ->
>     ?debugFmt("I am ~p ~p~n", [self(), erlang:process_info(self())]),
>     true = code:delete(a_mod),
>     ?debugFmt("processes using a_mod: ~p~n", [[P || P <- processes(), erlang:check_process_code(P, a_mod)]]),
>     true = code:soft_purge(a_mod),
>     ok.
> I looked into trying to patch this, but the eunit code is too convoluted
> for me to understand where it is holding the problematic reference.

I've had the same problem, and somehow discovered that it works if the
test generator function in A has a title.  That is, instead of:

my_test_() ->


my_test_() ->
    {"do something", ?_test(do_something())}.

That led me to think that Eunit holds on to the fun object as a "name"
if the test has no explicit title.


More information about the erlang-bugs mailing list