python - Execution of commands after unittest.main() -
i calling next script python script:
test.py logfile
it should run test , save result in logfile. reason commands after unittest.main(testrunner=runner)
not beingness executed. not sure if file gets closed after writing it. there way script it?!
from selenium import webdriver selenium.webdriver.common.by import selenium.webdriver.common.keys import keys selenium.webdriver.support.ui import select selenium.common.exceptions import nosuchelementexception 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 test " + testcase_name + " " + time.strftime("%c")) print(testcase_name," running!!!!") runner = unittest.texttestrunner(f) unittest.main(testrunner=runner) f.close() print(testcase_name," finished!!!!")
unittest.main
accepts optional parameter exit
. default value true
; cause sys.exit
called. explicitly pass false
prevent that.
... unittest.main(testrunner=runner, exit=false) ...
python unit-testing python-3.x python-unittest
No comments:
Post a Comment