The docs say that a unit test cleanup goal can share variables with the test body, but this doesn’t quite work:
:- set_prolog_flag(plunit_output, always).
test(fail_test, [ cleanup(writeln(user_output,Message)), fail ]) :-
Message = "cleanup message",
writeln(user_output, "testing"),
fail.
Looks like Message
must be introduced in a setup
goal instead — something to clarify in the docs.