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
  problem in using unittest akbarza 2 314 Feb-25-2024, 12:51 PM
Last Post: deanhystad
  python convert multiple files to multiple lists MCL169 6 1,547 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  error "cannot identify image file" part way through running hatflyer 0 679 Nov-02-2023, 11:45 PM
Last Post: hatflyer
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 962 Feb-15-2023, 05:34 PM
Last Post: zsousa
  Web project and running a .py file emont 0 642 Dec-11-2022, 11:15 PM
Last Post: emont
Question Unwanted execution of unittest ThomasFab 9 2,056 Nov-15-2022, 05:33 PM
Last Post: snippsat
  python run multiple file paralaly mg24 2 859 Oct-11-2022, 06:08 PM
Last Post: deanhystad
  unittest.mock for an api key silver 3 1,392 Aug-29-2022, 03:52 PM
Last Post: ndc85430
  Insert a multiple constant value after header in csv file using python shantanu97 1 1,147 Apr-24-2022, 10:04 AM
Last Post: Pedroski55
  batch file for running python scipt in Windows shell MaartenRo 2 1,893 Jan-21-2022, 02:36 PM
Last Post: MaartenRo

Forum Jump:

User Panel Messages

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