forked from samuel/python-ping
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathrun_tests.py
More file actions
44 lines (35 loc) · 1.16 KB
/
run_tests.py
File metadata and controls
44 lines (35 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import io
import os
import platform
import subprocess
import sys
import time
import unittest
def output_system_info(log):
pipe = subprocess.PIPE
p = subprocess.Popen(['git', 'log', '--oneline', '-n 1'], stdout=pipe,
stderr=pipe)
stdout, stderr = p.communicate()
p.kill()
log.writelines(item for item in [
'%s\n' % time.asctime(),
'os.name: %s\n' % os.name,
'platform.system: %s\n' % platform.system(),
'platform.release: %s\n' % platform.release(),
'commit: %s\n' % stdout.decode().split()[0],
'Python version (via sys.version): %s\n\n' % sys.version
])
def run_tests(log, v=2):
loader = unittest.TestLoader()
tests = loader.discover('tests')
# tests = loader.loadTestsFromName('builder')
runner = unittest.TextTestRunner(stream=log, buffer=True, verbosity=v)
runner.run(tests)
log = io.StringIO()
output_system_info(log)
run_tests(log)
# UNCOMMENT TO ADD TO tests.log
# with open('logs/tests.log', 'a+') as test_log:
# l.test_logger.info('Appending test results to tests log.')
# test_log.writelines([line for line in log.getvalue()])
print(log.getvalue())