Changed workflow on Sauce Lab jobs annotations. Now they are performend when all the tests end

This commit is contained in:
axl89 2016-05-27 18:26:47 +02:00
parent 1c94eee171
commit 612ad6ea70
2 changed files with 25 additions and 6 deletions

View File

@ -29,6 +29,7 @@ class PandoraWebDriverTestCase(TestCase):
sauce_username = environ["SAUCE_USERNAME"] sauce_username = environ["SAUCE_USERNAME"]
sauce_access_key = environ["SAUCE_ACCESS_KEY"] sauce_access_key = environ["SAUCE_ACCESS_KEY"]
sauce_client = None sauce_client = None
sauce_labs_job_id = None
desired_cap = { desired_cap = {
'tunnel-identifier': environ["TRAVIS_JOB_NUMBER"], 'tunnel-identifier': environ["TRAVIS_JOB_NUMBER"],
@ -41,6 +42,7 @@ class PandoraWebDriverTestCase(TestCase):
self.time_started = datetime.now() self.time_started = datetime.now()
#Start VM in Sauce Labs #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.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.sauce_client = SauceClient(self.sauce_username, self.sauce_access_key)
self.driver.implicitly_wait(30) self.driver.implicitly_wait(30)
@ -75,9 +77,6 @@ class PandoraWebDriverTestCase(TestCase):
diff = tack - self.time_started diff = tack - self.time_started
self.time_elapsed = diff.seconds self.time_elapsed = diff.seconds
self.driver.quit() 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) self.assertEqual([], self.verificationErrors)
super(PandoraWebDriverTestCase, self).tearDown() super(PandoraWebDriverTestCase, self).tearDown()

View File

@ -2,7 +2,9 @@
from unittest import * from unittest import *
from console.include.common_functions_60 import * from console.include.common_functions_60 import *
from console.include.common_classes_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): def get_test_file(test_list):
#return [test[0].split(' ')[0].split('.')[0].split('<')[1] for test in 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() c = ArticaTestResult()
tests.run(c) 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 failed: %s" % c.failures
print "Tests succeeded: %s" % c.success print "Tests succeeded: %s" % c.success
print "Tests skipped: %s" % c.skipped print "Tests skipped: %s" % c.skipped
print "Tests with errors: %s" % c.errors print "Tests with errors: %s" % c.errors
if (len(c.failures)+len(c.errors)+len(c.skipped)) != 0: if (len(c.failures)+len(c.errors)+len(c.skipped)) != 0:
exit(1) sys.exit(1)
else: else:
exit(0) sys.exit(0)