Parametrized Unit Tests

rambius rambiusparkisanius at
Fri Aug 21 17:17:32 CEST 2015


I am running one and the same unit tests that test some web application. I would like to execute them against different servers that may host different instances of the application.

So far I have something like

#!/usr/bin/env python

import unittest

server = ""
user = ""
password = ""

class MyTest(unittest.TestCase):

    def setUp(self):
        global server
        global user
        global password
        self.conn = MyConnection(server, user, password)

    def test_1(self):
        result = run_smth_1(self.conn)

    def test_2(self):
        result = run_smth_2(self.conn)

    def tearDown(self):

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-u', '--user',
    parser.add_argument('-p', '--password')
    parser.add_argument('-s', '--server')
    args = parser.parse_args()

    server = args.server
    user = args.user
    password = args.password


Is there a better a way to pass the server, the user and the password to the test without resolving to global variables?

Although I developed these tests as unit tests they are more of integration tests. Is there an integration testing framework that supports a more convenient passing of test parameters / data?

Thank you in advance for your responses.


More information about the Python-list mailing list