Nose test script with command line arguments

后端 未结 5 1449
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 06:54

I would like to be able to run a nose test script which accepts command line arguments. For example, something along the lines:

test.py

import nose, sys
         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 07:38

    I think that is a perfectly acceptable scenario. I also needed to do something similar in order to run the tests against different scenarios (dev, qa, prod, etc) and there I needed the right URLS and configurations for each environment.

    The solution I found was to use the nose-testconfig plugin (link here). It is not exactly passing command line arguments, but creating a config file with all your parameters, and then passing this config file as argument when you execute your nose-tests.

    The config file has the following format:

    [group1]
    env=qa
    
    [urlConfig]
    address=http://something
    
    [dbConfig]
    user=test
    pass=test
    

    And you can read the arguments using:

    from testconfig import config
    
    print(config['dbConfig']['user'])
    

提交回复
热议问题