[TIP] using py.test's setup_class with unittest tests?
Hans Sebastian
hnsbstn at gmail.com
Tue Nov 23 09:46:21 PST 2010
Hello testing in python members,
I need some help related to py.test and unittest. I have tests written and
run using unittest and now I also want py.test to be able to run it. The
problem is at the beginning of each suite in a test script there is a setup
that needs to be done. I need this setup function to be called as well when
run with py.test.
To illustrate my problem, I have a test script below and my goal is to be
able to run custom_setup() when run with unittest or py.test. The problem is
setup_class is not getting called. We use python 2.6.4 and py-1.2.1. Can
this be done? Thank you.
-hans
import logging
import unittest
logging.getLogger()
def custom_setup():
logging.info('custom setup')
class TestSimple(unittest.TestCase):
def setup_class(cls):
logging.info('setup_class')
custom_setup()
def setUp(self):
logging.info('setUp')
def test_1(self):
logging.info('test_1')
def test_2(self):
logging.info('test_2')
if __name__ == '__main__':
custom_setup()
suite = unittest.TestLoader().loadTestsFromTestCase(TestSimple)
unittest.TextTestRunner(verbosity=2).run(suite)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20101123/686eb776/attachment.html>
More information about the testing-in-python
mailing list