Is it possible to skip the setUp and tearDown functions for a test..? Please let me know how. Thank you
Asked
Active
Viewed 1,071 times
1 Answers
0
The only way to do this without writing another test class with different setUp
and tearDown
methods seems to be to overwrite the run
method of TestCase
.
You can either rewrite it totally or try this shorter version (only for the setUp
, but you can easily extend it to support tearDown
too):
class MyTestCase(unitest.TestCase):
def run(self, result=None):
if self._testMethodName == 'testWithoutSetup':
(old_setUp, self.setUp) = (self.setUp, lambda : None)
try:
super(MyTestCase, self).run(result)
finally:
self.setUp = old_setUp
else:
super(MyTestCase, self).run(result)
What I do is I test if the method being tested is named testWithoutSetup
, and if it is, I temporaly replace the setUp
method with a function that does nothing.
Note that I only tested with Python 3.3, and it may work only for this version.

Valentin Lorentz
- 9,556
- 6
- 47
- 69
-
oh yea got it.. I have got another question which I posted here [link](http://stackoverflow.com/questions/22144990/pyunit-framework-extending-the-classes-of-unittest), if anybody could answer that it is really helpful. thank you – user2511126 Mar 03 '14 at 20:44