Executing commands after unittest.main ()

I am calling the following script from another Python script:

test.py logfile

It should run the test and save the result to a log file. But for some reason the commands after are unittest.main(testRunner=runner)

not executed. I'm not even sure if the file is closed after writing it. Is there any other way to script it ?!

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re, sys

    class SeleniumYahooTest(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Firefox()
            self.driver.implicitly_wait(30)
            self.base_url = "https://www.yahoo.com"
            self.verificationErrors = []
            self.accept_next_alert = True
       . 
       .
       .

        def tearDown(self):
            self.driver.quit()
            self.assertEqual([], self.verificationErrors)


if __name__ == '__main__':

if len(sys.argv)>1:
   testcase_name = sys.argv[0]
   result_file = sys.argv[1]
   del(sys.argv[1:])
f = open(result_file, "a")
result_file.write("This is Test " + testcase_name + " " + time.strftime("%c"))
print(testcase_name," is running!!!!")
runner = unittest.TextTestRunner(f)
unittest.main(testRunner=runner)
f.close()
print(testcase_name," is finished!!!!")

      

+3


source to share


1 answer


unittest.main

takes an optional parameter exit

. The default for it is True

; call sys.exit

. Explicitly committing False

to prevent this.



...
unittest.main(testRunner=runner, exit=False)
...

      

+3


source







All Articles