Python unittest - running multiple tests from CSV file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python unittest - running multiple tests from CSV file (/thread-15539.html) |
Python unittest - running multiple tests from CSV file - asheru93 - Jan-21-2019 class TestSuites(unittest.TestCase): def completeTest(self): pathCSV = r'pathToCSV\testCSV.csv' with open(pathCSV, 'rb') as csvfile: reader = csv.reader(csvfile) for row in reader: for item in row: try: getattr(MyFile.myClass, item)() except AttributeError: print("Unknown attribute", item, "ignored") @staticmethod def myTests(): suite = unittest.TestSuite() suite.addTest(TestSuites('completeTest')) return suite if __name__== "__main__": runner.run(MyFile.TestSuites.myTests())I have this piece of code wich reads a CSV file and runs a test(completeTest). The CSV file looks like this: startApp,stopApp startApp,createNewProject,stopApp so each line in the CSV should be a test. Now everything that comes from the CSV lies under one test in my code. I want to run a test for each line in the CSV? How can I do this? Thank you |