Python Forum
Python unittest - running multiple tests from CSV file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python unittest - running multiple tests from CSV file
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Running script on multiple files Afrodizzyjack 1 750 May-14-2021, 10:49 PM
Last Post: Yoriz
  Running A Parser In VSCode - And Write The Results Into A Csv-File apollo 5 1,428 Jan-14-2021, 08:58 PM
Last Post: snippsat
Sad Problem with Unittest mhanusek 1 793 Nov-12-2020, 04:58 PM
Last Post: Gribouillis
  Unittest et patch mad31 2 761 Aug-09-2020, 06:16 AM
Last Post: mad31
  WinError 87 while running .exe file Timych 0 1,055 Aug-06-2020, 02:36 PM
Last Post: Timych
  Unusual things to do with unittest/HTMLTestRunner AndyHolyer 0 667 Jul-29-2020, 02:43 PM
Last Post: AndyHolyer
  VSCode not able to discover tests rpk2006 5 2,679 Jul-15-2020, 06:03 AM
Last Post: ndc85430
  Test a class function via "unittest " Penguin827 1 695 Jul-10-2020, 08:31 AM
Last Post: Gribouillis
  Python call/running another python file windows11 7 1,257 Jun-12-2020, 10:13 AM
Last Post: windows11
  StopIteration exception when mock PostgreSQL connection in several tests igor87z 1 1,010 Jun-10-2020, 06:16 PM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020