forked from Informatinks/ejudge-listener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
36 lines (26 loc) · 817 Bytes
/
cli.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
import os
import sys
import unittest
import click
from flask.cli import with_appcontext
THIS_FILE = os.path.abspath(os.path.dirname(__file__))
TESTS_DIR = os.path.join(THIS_FILE, 'tests/')
@click.command('test')
@click.option('--teamcity', is_flag=True, default=False)
@click.option('--verbosity', '-v', default=2)
@with_appcontext
def test(teamcity, verbosity):
loader = unittest.TestLoader()
tests = loader.discover(TESTS_DIR, pattern='test*.py')
if teamcity:
from teamcity.unittestpy import TeamcityTestRunner
runner = TeamcityTestRunner()
else:
runner = unittest.TextTestRunner(verbosity=verbosity)
result = runner.run(tests)
exit_code = 1
if result.wasSuccessful():
exit_code = 0
sys.exit(exit_code)
if __name__ == '__main__':
test()