Re: [Pyunit-interest] Argument passing question
Brought to you by:
purcell
From: Steve P. <ste...@ya...> - 2001-07-19 05:43:23
|
Hello Russell, Sorry for the delay in responding to your posting. Russell Shotts wrote: > I am evaluating PyUnit for a testing framework I need at work. I'm running > into one small problem. One of our requirements is to execute each test > once for each file in a rather large set of input files. Ideally, I need a > mechanism to iterate over the files in the file set, and execute each test > suite once (and subsequently, each test case within the suite) once for the > given file. I don't see any real hooks to pass arguments to the test suite > or test case. If the results of all the tests are expected to be the same for every possible set of input files, then the input files really constitute an 'environment' in which you run your suite of tests. (If different results were expected for different input files, then each test/file combination would be a distinct TestCase.) The simplest solution would be to write a module which provides a configurable singleton environment object. In your case, the environment object would represent a group of input files. #--- my_test_environment.py class Environment: def __init__(self, input_file1, input_file2): self.input_file1 = input_file1 self.input_file2 = input_file2 environment = None def initialise(*args, **kwargs): global environment environment = apply(Environment, args, kwargs) # set a default environment initialise('./data/file1', './data/file2') Then, you make your tests access the names of the files they should open via the Environment object 'my_test_environment.environment'. You can run all your tests against the default set of files without changing any further code. To run the tests against all your different sets of files, you can alter the environment object before running tests: my_test_environment.initialise('./other_data/file1', './other_data/file2') load_and_run_all_tests() # with TestLoader/TextTestRunner, for example my_test_environment.initialise('./more_data/file1', './more_data/file2') load_and_run_all_tests() You can obviously automate this process of looping over input file sets. Does that help? -Steve -- Steve Purcell, Pythangelist Get testing at http://pyunit.sourceforge.net/ Test your web apps with http://webunit.sourceforge.net/ |