Reputation: 5726
I have a list of different audioformats, to which a certain file should be converted. The conversion function i have written, should now convert the file and return information on success, the path to the newly created file or some failure information.
self.AUDIO_FORMATS = ({'format':'wav', 'samplerate':44100, 'bitdepth':16 },
{'format':'aac', 'samplerate':44100, 'bitdepth':16 },
{'format':'ogg', 'samplerate':44100, 'bitdepth':16 },
{'format':'mp3', 'samplerate':44100, 'bitdepth':16 } )
As one possible reason for one of the conversions failing is a missing library, or some bug or failure in such a library or my implementation of it, i want to test each of the conversions to have a list of passed and failed tests in the end, where the failed ones tell me exactly which conversion did cause the trouble. This is what i tried (a bit simplified):
def test_convert_to_formats(self):
for options in self.AUDIO_FORMATS:
created_file_path, errors = convert_audiofile(self.audiofile,options)
self.assertFalse( errors )
self.assertTrue( os.path.isfile(created_file_path),
Now this is, of course, aborting the test as soon as the first conversion fails. I could write a test function for each of the conversions. That would result in having to write a new test for each added format, where now i just have to add a new dictionary to my AUDIO_FORMATS tuple.
Upvotes: 1
Views: 79
Reputation: 1378
why not use try...except... ?
errors = []
for option in optionlist:
try:
assert_and_raise1(option)
assert_and_raise2(...)
except Exception, e:
errors.append("[%s] fail: %s"%(option, e))
for e in errors:
print e
Upvotes: 0
Reputation: 140050
Instead of asserting, store the errors in an array. At the end of your iteration, assert that the errors array is empty and potentially dump the contents of the array as the assertion failure reason.
Upvotes: 6