Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
szabgab opened this issue Feb 23, 2021 · 0 comments

Comments

@szabgab
Copy link
Collaborator

szabgab commented Feb 23, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant