From 896570821e8a8b5479eccd4efcd90fc48c9236c8 Mon Sep 17 00:00:00 2001 From: axl89 Date: Fri, 27 May 2016 18:32:42 +0200 Subject: [PATCH] Changed workflow on Sauce Lab jobs annotations. Now they are performend when all the tests end --- tests/console/include/common_classes_60.py | 5 ++--- tests/run_console_tests.py | 26 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/tests/console/include/common_classes_60.py b/tests/console/include/common_classes_60.py index 9e203fb214..6ff7c10634 100644 --- a/tests/console/include/common_classes_60.py +++ b/tests/console/include/common_classes_60.py @@ -29,6 +29,7 @@ class PandoraWebDriverTestCase(TestCase): sauce_username = environ["SAUCE_USERNAME"] sauce_access_key = environ["SAUCE_ACCESS_KEY"] sauce_client = None + sauce_labs_job_id = None desired_cap = { 'tunnel-identifier': environ["TRAVIS_JOB_NUMBER"], @@ -41,6 +42,7 @@ class PandoraWebDriverTestCase(TestCase): self.time_started = datetime.now() #Start VM in Sauce Labs self.driver = webdriver.Remote(command_executor='http://'+self.sauce_username+':'+self.sauce_access_key+'@ondemand.saucelabs.com:80/wd/hub',desired_capabilities=self.desired_cap) + self.sauce_labs_job_id = self.driver.session_id # We store this information to update the job info when the tests are done self.sauce_client = SauceClient(self.sauce_username, self.sauce_access_key) self.driver.implicitly_wait(30) @@ -75,9 +77,6 @@ class PandoraWebDriverTestCase(TestCase): diff = tack - self.time_started self.time_elapsed = diff.seconds self.driver.quit() - #Update Sauce Labs job - is_test_successful = self.verificationErrors == [] - self.sauce_client.jobs.update_job(self.driver.session_id, passed=is_test_successful,tags=[environ["TRAVIS_BRANCH"],self.id()],build_num=environ["TRAVIS_JOB_NUMBER"],name=str(environ["TRAVIS_COMMIT"])+"_"+str(self.id().split('.')[1])) self.assertEqual([], self.verificationErrors) super(PandoraWebDriverTestCase, self).tearDown() diff --git a/tests/run_console_tests.py b/tests/run_console_tests.py index 7cbef38c10..13308706b8 100755 --- a/tests/run_console_tests.py +++ b/tests/run_console_tests.py @@ -2,7 +2,9 @@ from unittest import * from console.include.common_functions_60 import * from console.include.common_classes_60 import * -import subprocess, os, time +from sauceclient import SauceClient +from os import environ +import subprocess, time, sys def get_test_file(test_list): #return [test[0].split(' ')[0].split('.')[0].split('<')[1] for test in test_list] @@ -13,13 +15,31 @@ tests = a.discover(start_dir='console',pattern='PAN*.py') c = ArticaTestResult() tests.run(c) +#Update Saouce Labs jobs +sauce_client = SauceClient(environ["SAUCE_USERNAME"], environ["SAUCE_ACCESS_KEY"]) +for test,error_msg in c.failures+c.skipped+c.errors: + try: + sauce_client.jobs.update_job(test.sauce_labs_job_id, passed=False,tags=[environ["TRAVIS_BRANCH"],test.id()],build_num=environ["TRAVIS_JOB_NUMBER"],name=str(environ["TRAVIS_COMMIT"])+"_"+str(test.id().split('.')[1])) + except: + print "Could not annotate Sauce Labs job #%s" % str(test.sauce_labs_job_id) + next + +for test,error_msg in c.success: + try: + sauce_client.jobs.update_job(test.sauce_labs_job_id, passed=True,tags=[environ["TRAVIS_BRANCH"],test.id()],build_num=environ["TRAVIS_JOB_NUMBER"],name=str(environ["TRAVIS_COMMIT"])+"_"+str(test.id().split('.')[1])) + except: + print "Could not annotate Sauce Labs job #%s" % str(test.sauce_labs_job_id) + next + + + print "Tests failed: %s" % c.failures print "Tests succeeded: %s" % c.success print "Tests skipped: %s" % c.skipped print "Tests with errors: %s" % c.errors if (len(c.failures)+len(c.errors)+len(c.skipped)) != 0: - exit(1) + sys.exit(1) else: - exit(0) + sys.exit(0)