File: run_one.py

package info (click to toggle)
sasdata 0.11.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,424 kB
  • sloc: xml: 11,476; python: 8,268; makefile: 48; sh: 7
file content (33 lines) | stat: -rw-r--r-- 1,053 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python
import os
import sys
import xmlrunner
import unittest
import importlib.util
from os.path import abspath, split as splitpath

import logging
logger = logging.getLogger(__name__)
if not logger.root.handlers:
    import logging.config
    LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'logging.ini')
    logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=False)

if len(sys.argv) < 2:
    logger.error("Use %s <filename to test>", sys.argv[0])
    sys.exit(-1)

test_path_abs = abspath(sys.argv[1])
test_path, f_name_full = splitpath(abspath(sys.argv[1]))
f_name = f_name_full.split('.')[0]
#print("=== testing:", sys.argv[1])
sys.argv = [sys.argv[0]]
os.chdir(test_path)
sys.path.insert(0, test_path)
#print("\n".join(sys.path))
foo = importlib.util.spec_from_file_location('tests', f_name_full)
test = importlib.util.module_from_spec(foo)
sys.modules['tests'] = test
foo.loader.exec_module(test)
#print(test)
unittest.main(test, testRunner=xmlrunner.XMLTestRunner(output='logs'))