[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.


import logging
import unittest

def custom_setup():
    logging.info('custom setup')

class TestSimple(unittest.TestCase):

    def setup_class(cls):

    def setUp(self):

    def test_1(self):

    def test_2(self):

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(TestSimple)
-------------- 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