dimanche 29 novembre 2015

how can I pass argument(s) through nose.run that can be picked up by list of python test files containing test methods

I am creating a series of tests with python unittest and executing them with nosetest module.

I am trying to figure out how do i pass an argument(s), for example environment or domain, so that the value would be passed the actual test method being executed.

I have a runner python script which passes test suite class file and environment as arguments

python runner.py --suite=generic_pass.py --env=dev.domain.com

The runner.py picks up the suite value and passes it to test_suite in nose.run method within "runner.py"

Contents of runner.py

nose.run(argv=["", test_suite, "--verbosity=2"])

The contents of test_suite or "generic_pass.py" script are as follows

class loginTest(login.userLoginTest):
     pass
class logoutTest(logout.userLogoutTest):
     pass

The contents of login.py

class userLoginTest(unittest.TestCase):
     def setUp(self):
         self.login = userLogin(user,pass,environment)
     def test_response(self):
         self.assertEquals(200, getResponse(self.login))

When python runner.py script is executed, it then runs nose.run, which then executes the tests specified in generic_pass.py (test_suite)

I am trying to figure out, how can i pass the contents of --env "dev.domain.com" from runner.py to each test case class file though nose.run() method, so that i could use it in

self.login = userLogin(user,pass,environment)

which is located in login.py

Aucun commentaire:

Enregistrer un commentaire