[unittest] Run setUp only once

N

Nikolaus Rath

Hello,

I have a number of conceptually separate tests that nevertheless need
a common, complicated and expensive setup.

Unfortunately, unittest runs the setUp method once for each defined
test, even if they're part of the same class as in

class TwoTests(unittest.TestCase):
def setUp(self):
# do something very time consuming

def testOneThing(self):


def testADifferentThing(self):


which would call setUp twice.


Is there any way to avoid this, without packing all the unrelated
tests into one big function?


Best,

-Nikolaus

--
»It is not worth an intelligent man's time to be in the majority.
By definition, there are already enough people to do that.«
-J.H. Hardy

PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top