forked from pcdshub/pcdsdevices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
49 lines (41 loc) · 1.46 KB
/
run_tests.py
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
45
46
47
48
49
#!/usr/bin/env python
import sys
import os
import logging
from pathlib import Path
from logging.handlers import RotatingFileHandler
import pytest
if __name__ == '__main__':
# Show output results from every test function
# Show the message output for skipped and expected failures
args = ['-v', '-vrxs']
# Add extra arguments
if len(sys.argv) > 1:
args.extend(sys.argv[1:])
txt = 'pytest arguments: {}'.format(args)
print(txt)
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
log_dir = Path(os.path.dirname(__file__)) / 'logs'
log_file = log_dir / 'run_tests_log.txt'
if not log_dir.exists():
log_dir.mkdir(parents=True)
if log_file.exists():
do_rollover = True
else:
do_rollover = False
handler = RotatingFileHandler(str(log_file), backupCount=5,
encoding=None, delay=0)
if do_rollover:
handler.doRollover()
formatter = logging.Formatter(fmt=('%(asctime)s.%(msecs)03d '
'%(module)-13s '
'%(levelname)-8s '
'%(threadName)-10s '
'%(message)s'),
datefmt='%H:%M:%S')
handler.setFormatter(formatter)
root_logger.addHandler(handler)
logger = logging.getLogger(__name__)
logger.info(txt)
sys.exit(pytest.main(args))