minimal adjustments
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-python / pythonFiles / testlauncher.py
1 # Copyright (c) Microsoft Corporation. All rights reserved.
2 # Licensed under the MIT License.
3
4 import os
5 import sys
6
7
8 def parse_argv():
9     """Parses arguments for use with the test launcher.
10     Arguments are:
11     1. Working directory.
12     2. Test runner, `pytest` or `nose`
13     3. Rest of the arguments are passed into the test runner.
14     """
15
16     return (sys.argv[1], sys.argv[2], sys.argv[3:])
17
18
19 def exclude_current_file_from_debugger():
20     # Load the debugger package
21     try:
22         import ptvsd
23         import ptvsd.debugger as vspd
24         vspd.DONT_DEBUG.append(os.path.normcase(__file__))
25     except:
26         traceback.print_exc()
27         print('''
28 Internal error detected. Please copy the above traceback and report at
29 https://github.com/Microsoft/vscode-python/issues/new
30
31 Press Enter to close. . .''')
32         try:
33             raw_input()
34         except NameError:
35             input()
36         sys.exit(1)
37
38
39 def run(cwd, testRunner, args):
40     """Runs the test
41     cwd -- the current directory to be set
42     testRunner -- test runner to be used `pytest` or `nose`
43     args -- arguments passed into the test runner
44     """
45     
46     sys.path[0] = os.getcwd()
47     os.chdir(cwd)
48
49     try:
50         if testRunner == 'pytest':
51             import pytest
52             pytest.main(args)
53         else:
54             import nose
55             nose.run(argv=args)
56         sys.exit(0)
57     finally:
58         pass
59
60
61 if __name__ == '__main__':
62     exclude_current_file_from_debugger()
63     cwd, testRunner, args = parse_argv()
64     run(cwd, testRunner, args)