Skip to content

Test::Class modules in aggregate test run leak into subsequent run modules #44

@szabgab

Description

@szabgab

In our test suite we have some Test::Class modules that all inherit from a subclass of Test::Class, and get run by a .t file that does the following:

use Test::Class::Load "./t/classes";
Test::Class->runtests;

We have recently been debugging some tests that create a mock object in their 'setup' method, and store it against $_[0]{mocked}, and it looks like this doesn't get destroyed once the test class module has finished running and moved onto the next module, which means our mocked objects leak into our next tests.

I can't think of a case where this behaviour would be the desired one, I'd have thought the objects should get cleaned up once we've moved onto the next test class.

Looking at the implementation, it seems the cause is this line in runtests:

  foreach my $t (@tests) {
     # stuff
     $t = $t->new unless ref($t);

Since $t is an alias to an element of @tests, it won't be destroyed until the runtests method ends. You could just use a different variable to store the instance.

Original: https://rt.cpan.org/Ticket/Display.html?id=100411

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions