What I would like to do, is create a folder, where people can put in a file for testing, and have pyunit automatically expand in order to run the test as a separate test. Currently, what I'm doing is:
class TestName(unittest.testcase):
def setUp(self):
for file in os.listdir(DIRECTORY):
# Setup Tests
def test_comparison(self):
for file in os.listdir(DIRECTORY):
# Run the tests
def suite():
return unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(TestName),
])
if __name__ == "__main__":
unittest.TextTestRunner(verbosity=2).run(suite())
Obviously there is many problems with that, such as if any test fails, the whole thing fails, etc. etc. What I would like to do, is set up pyunit so that it will run a test (or a test case), for each file that is placed in the directory. Now, what I'm thinking I could do is create the class listed above, with just the two methods, but in order to do that successfully, I would have to add in a context parameter, eg:
def setUp(self, filepath):
# Do stuff
Then I could put the loop in the main chunk of code, and run the tests like this:
def suite():
return unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(TestName, file),
])
if __name__ == "__main__":
for file in DIRECTORY:
unittest.TextTestRunner(verbosity=2).run(suite(file))
But I'm not sure how to do that without nearly rewriting the hole unittest.TestCase() class. Is there any way I could do that, or is there any other way I can geta dynamically expanding set of tests/test cases depending on how many files are in a folder? Thanks.