cannot run TestCase with more than 1 test method

Bug #1393919 reported by Monica
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
testtools
Invalid
Undecided
Unassigned

Bug Description

After upgrading from 0.9.34 to 0.9.36, I am no longer able to run any TestCases that have more than one test method in them. The issue derives from the following change to testtools:

https://github.com/rbtcollins/testtools/commit/5c3b92d90a64efaecdc4010a98002bfe8b888517

I see testtools.TestCase.setUp() called for the first time before the first test method is run. This test method executes successfully. Then I see testtools.TestCase.setUp() called again prior to the second test method in that class. At this point I get the following error message:

    "TestCase.setUp was already called. Do not explicitly call setUp from your tests. In your own setUp, use super to call the base setUp."

The expectation that setUp() is called only once per TestCase seems incorrect. Setup and teardown will get called multiple times, flanking each test method in the TestCase.

Looking at the code change for testtools.TestCase (link above) I would expect self.__setup_called to be reset to False in the tearDown method.

Revision history for this message
Monica (mraj) wrote :

Starting with testtools 0.9.34 I can cause the bug to happen if I introduce the code change linked in the bug description and I can fix the behaviour by setting self.__setup_called to false in testtools.TestCase.tearDown

Revision history for this message
Robert Collins (lifeless) wrote :

The expectation in unittest is that a single TestCase instance is only ever used to run a single TestCase method, and only once. I'm going to guess that you're creating one TestCase instance and then running many test methods on it. Why are you doing that?

Changed in testtools:
status: New → Incomplete
Revision history for this message
Monica (mraj) wrote :

I'm working with some legacy code that loads tests in this manner. It sounds like this method of test loading is against the expected behavior of unittest so the issue is on my side. I have updated the bug to 'Invalid' state

Changed in testtools:
status: Incomplete → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.