[Perlunit-users] Doing assertions in tear_down() masks previous failed assertions
Status: Beta
Brought to you by:
mca1001
From: Desilets, A. <Ala...@nr...> - 2011-09-09 13:14:59
|
I have a tests JobQueueTest, which tests a queue that can be shared between processes. In the tear_down() of JobQueueTest, I want to make sure that the test did not leave the queue in a lock state (clients that use a JobQueue are not supposed to ever be able to end up with that kind of locked state). sub tear_down { my ($self) = @_; # # If a test leaves the queue in a locked state, it's probably a sign # of an unbalanced lock/unlock pair. # $self->assert(!defined($self->{queue}->_already_locked_by_me()), "This test left the queue in a locked state.\n". "This is probably a sign that there is an unbalanced lock/unlock pair somewhere in the code."); } The problem is that this assertion ends up masking any failure that may happen in the course of carrying out the test. For example, if test itself carries out an assertion that fails with error message X, then instead of seing error X, I will see the above error message regarding the lock state. This is very misleading and prevents me from knowing the actual root of the problem. Is there a way around this? For example, in my tear_down(), could I check to see if some exceptions have already been raised in this test, and if so, not assert for consistency of the instance under test? Thx |