I am writing a test script that contains different functions for different tests. I would like to be able to randomly select a test to run. I have already achieved this with the following function ...
test_options = ("AOI", "RMODE")
def random_test(test_options, control_obj):
ran_test_opt = choice(test_options)
if ran_test_opt.upper() == "AOI":
logging.debug("Random AOI Test selected")
random_aoi()
elif ran_test_opt.upper() == "RMODE":
logging.debug("Random Read Mode Test selected")
random_read_mode(control_obj)
However, I want to add additional test functions without having to change the selective testing function. All I would like to do is add to the test function to the script. In addition, I would also like to choose which test will be included in the random selection. This is what the test_options variable does. How can I change the random generation function to achieve this?
EDIT: I circumvented the fact that all tests might require different arguments by including them in the test class. All arguments will be passed to init, and testing functions will refer to them using the "I". when they need a specific variable ...
class Test(object):
"""A class that contains and keeps track of the tests and the different modes"""
def __init__(self, parser, control_obj):
self.parser = parser
self.control_obj = control_obj
def random_test(self):
test_options = []
for name in self.parser.options('Test_Selection'):
if self.parser.getboolean('Test_Selection', name):
test_options.append(name.lower())
ran_test_opt = choice(test_options)
ran_test_func = getattr(self, ran_test_opt)
ran_test_func()
def random_aoi(self):
logging.info("Random AOI Test")
self.control_obj.random_readout_size()
def random_read_mode(self):
logging.info("Random Readout Mode Test")
self.control_obj.random_read_mode()
source
share