Eunit - Omitting System Reports during Testing?

Hi there,
so I’m finishing up the packaging of a lib. My last issue is, how on earth do I omit the System reporting?
When running Eunit it by default swallows IO output to the console. I’ve tried adding a profile to rebar3, with:

{profiles, [{test, [{kernel, [various_options_for_logger]}]}]}.

But I was unable to? Any tips?
(btw rebar3+eunit+cover+dialyzer == <3)

I’m not sure what you mean, unless you meant “emit” instead of “omit”?

1 Like

Ah - I meant the Reports still appear during the test runs, like when a child crashes you get the supervisor/system report on it and I would like to “silence” them during eunit runs, since I’m crashing things on purpose and it “pollutes” the output with a lot of logs?

1 Like

Oh, you said it was swallowing IO output which is what confused me.

So it is logger output that is the issue? Maybe something broke with the IO capture. /cc @ferd

2 Likes

You’re right, what I wrote doesn’t make sense because I erased part of it before submitting and left that there -_- but yes the the reports DO show on the output and that’s what I want to silence.

EUnit by default captures nothing, and we have added nothing about this either.

We do have an equivalent that exists for Common Test.

If you want to do it in EUnit, you can silence or change the logging level through the setup fixtures. Just call logger:add_handler_filter(default, ?MODULE, {fun(_,_) -> stop end, nostate}) and remove it with logger:remove_handler_filter(default, ?MODULE); at the end of the test.

To do it for all runs, you might want to add the filter_default value to stop to kill it all. I’m not sure whether we do live-reload of configs for eunit the way we do it for CT. That wouldn’t be too hard to add if it’s not there though.

2 Likes

Hi! This does indeed silence the “Supervisor Reports”, but the “Crash Reports” and “Error Reports” still get to the console.

===> Performing EUnit tests...
.................=ERROR REPORT==== 9-Aug-2019::13:12:13.271065 ===
** Generic server workforce_watcher terminating 
** Last message in was {'EXIT',<0.376.0>,killed}
** When Server state == {state,{test_worker,start_link,[]},
                               #{<0.379.0> => true,<0.380.0> => true,
                                 <0.381.0> => true,<0.382.0> => true,
                                 <0.383.0> => true,<0.384.0> => true,
                                 <0.385.0> => true,<0.386.0> => true,
                                 <0.387.0> => true,<0.388.0> => true}}
** Reason for termination ==
** killed

=CRASH REPORT==== 9-Aug-2019::13:12:13.271453 ===
  crasher:
    initial call: workforce_watcher:init/1
    pid: <0.377.0>
    registered_name: workforce_watcher
    exception exit: killed
      in function  gen_server:decode_msg/9 (gen_server.erl, line 432)
    ancestors: [workforce_supervisor,<0.210.0>]
    message_queue_len: 19
    messages: [{started,<0.378.0>,<0.380.0>,nil},
                  {started,<0.378.0>,<0.381.0>,nil},
                  {started,<0.378.0>,<0.382.0>,nil},
....

(btw the guide on eunit helped a bunch getting started with it)

If you’re using SASL in your app, you might want to configure it with application:set_env(sasl, sasl_error_logger, false) to turn these off.

I’m not recalling off the top of my head where these lines are coming from if not from there.

1 Like

That didn’t work either - I’m not explicitly using the sasl application anywhere though (by what I understood now by default those errors get logged through the regular logger interface? so your first tip should have worked).

Anyway I added this as the first test to the suite
{"Turn off logs", fun() -> logger:set_primary_config(level, none) end},

And now it goes fine:

rebar3 eunit
===> Verifying dependencies...
===> Compiling workforce
===> Performing EUnit tests...
....................
Finished in 0.284 seconds
20 tests, 0 failures

and still shows errors if there are any. Thanks again!

So, I probably didn’t save the changes the second time I ran it (?), because I tried now adding the handler_filter you gave at the start of the suit and indeed it does work… As expected… Thanks!