Skip to content
Snippets Groups Projects
Commit dc272d6b authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Added email if fail in tester args (refs #20227).

parent 8699399d
No related branches found
No related tags found
No related merge requests found
...@@ -35,11 +35,13 @@ sys.stderr = sys.stdout ...@@ -35,11 +35,13 @@ sys.stderr = sys.stdout
class Tester(): class Tester():
USAGE = '''%s [-e] [-b] [-d] [-h] USAGE = '''%s [-e] [-f] [-b] [-d] [-h]
-e: send email with report. -e: send email with report.
-f: send email with report only if at least one test failed.
-b: run only basic tests (exclude mediaserver tests). -b: run only basic tests (exclude mediaserver tests).
-d: debug mode (can be started with non root users). -d: debug mode (can be started with non root users).
-h: show this message.''' % __file__ -h: show this message.''' % __file__
VALID_ARGS = ['-e', '-f', '-b', '-d', '-h']
def __init__(self, *args): def __init__(self, *args):
log('\033[96m-------------------------------\033[0m') log('\033[96m-------------------------------\033[0m')
...@@ -50,6 +52,11 @@ class Tester(): ...@@ -50,6 +52,11 @@ class Tester():
if '-h' in args: if '-h' in args:
log('USAGE: ' + self.USAGE) log('USAGE: ' + self.USAGE)
sys.exit(0) sys.exit(0)
for arg in args:
if arg not in self.VALID_ARGS:
log('Invalid argument given: "%s".\n' % arg)
log('USAGE: ' + self.USAGE)
sys.exit(1)
# Check current dir # Check current dir
root_dir = utils.get_dir(__file__) root_dir = utils.get_dir(__file__)
if root_dir != '': if root_dir != '':
...@@ -71,11 +78,12 @@ class Tester(): ...@@ -71,11 +78,12 @@ class Tester():
sys.exit(1) sys.exit(1)
# Check for email value # Check for email value
email = '-e' in args email = '-e' in args
email_if_fail = '-f' in args
basic_only = '-b' in args basic_only = '-b' in args
tests = self.discover_tests(basic_only) tests = self.discover_tests(basic_only)
if not tests: if not tests:
sys.exit(1) sys.exit(1)
exit_code = self.run_tests(tests, email) exit_code = self.run_tests(tests, email, email_if_fail)
sys.exit(exit_code) sys.exit(exit_code)
def get_file_description(self, path): def get_file_description(self, path):
...@@ -150,7 +158,7 @@ class Tester(): ...@@ -150,7 +158,7 @@ class Tester():
tests.append(('%s (%s)' % (name, user), description, [test_path, user])) tests.append(('%s (%s)' % (name, user), description, [test_path, user]))
return tests return tests
def run_tests(self, tests, email=False): def run_tests(self, tests, email=False, email_if_fail=False):
results = list() results = list()
exit_code = 0 exit_code = 0
# Run all tests # Run all tests
...@@ -194,7 +202,7 @@ class Tester(): ...@@ -194,7 +202,7 @@ class Tester():
html_report += '\n<tr><td>%s</td><td>%s</td><td>%s</td></tr>' % (name, html_result, description.replace('\n', '<br/>\n')) html_report += '\n<tr><td>%s</td><td>%s</td><td>%s</td></tr>' % (name, html_result, description.replace('\n', '<br/>\n'))
html_report += '\n</table>' html_report += '\n</table>'
# Send email # Send email
if email: if email or email_if_fail and exit_code != 0:
log('') log('')
hostname = subprocess.check_output(['hostname']) hostname = subprocess.check_output(['hostname'])
if not hostname: if not hostname:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment