pytest and nosetest added
authorIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Wed, 9 Dec 2015 20:17:21 +0000 (23:17 +0300)
committerIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Wed, 9 Dec 2015 20:17:21 +0000 (23:17 +0300)
python/helpers/pycharm/_jb_tox_runner.py

index 9d773dd9d80648ae0ca2ddd814d7e8e3c27d1f2a..6a297cf5948b30aac09c38d89a00db7e573939a8 100644 (file)
@@ -1,7 +1,8 @@
 # coding=utf-8
 """
 Runs tox from current directory.
 # coding=utf-8
 """
 Runs tox from current directory.
-It supports any runner, but well-known runners (py.test and unittest) are switched to our internal runners to provide better support
+It supports any runner, but well-known runners (py.test and unittest) are switched to our internal runners to provide
+better support
 """
 import os
 import sys
 """
 import os
 import sys
@@ -13,12 +14,30 @@ from tcmessages import TeamcityServiceMessages
 
 helpers_dir = str(os.path.split(__file__)[0])
 
 
 helpers_dir = str(os.path.split(__file__)[0])
 
-# Placeholder to insert arguments
-__ARGUMENTS_KEY = "__jb_place_for_arguments"
 
 
+class _Unit2(object):
+    def fix(self, command):
+        if command[0] != "unit2":
+            return None
+        return [os.path.join(helpers_dir, "utrunner.py"), os.getcwd()] + command[1:] + ["true"]
 
 
-# List of local runners to use
-_RUNNERS = {"unit2": [os.path.join(helpers_dir, "utrunner.py"), os.getcwd(), __ARGUMENTS_KEY, "true"]}
+
+class _PyTest(object):
+    def fix(self, command):
+        if command[0] != "py.test":
+            return None
+        return [os.path.join(helpers_dir, "pytestrunner.py"), "-p", "pytest_teamcity", os.getcwd()] + command[1:]
+
+
+class _Nose(object):
+    def fix(self, command):
+        if command[0] != "nosetests":
+            return None
+        return [os.path.join(helpers_dir, "noserunner.py"), os.getcwd()] + command[1:]
+
+
+
+_RUNNERS = [_Unit2(), _PyTest(), _Nose()]
 
 teamcity = TeamcityServiceMessages()
 
 
 teamcity = TeamcityServiceMessages()
 
@@ -60,19 +79,14 @@ for env, tmp_config in config.envconfigs.items():
         tmp_config.setenv = dict()
     tmp_config.setenv.update({"_jb_do_not_call_enter_matrix": "1"})
     commands = tmp_config.commands
         tmp_config.setenv = dict()
     tmp_config.setenv.update({"_jb_do_not_call_enter_matrix": "1"})
     commands = tmp_config.commands
-    if isinstance(commands, list) and len(commands):
-        command_with_arguments = commands[0]
-        command = command_with_arguments[0]
-        arguments = command_with_arguments[1:]
-        if command in _RUNNERS:
-            command_with_arguments = list(_RUNNERS[command_with_arguments[0]])
-            index_key = command_with_arguments.index(__ARGUMENTS_KEY)
-            if index_key:
-                if arguments:
-                    command_with_arguments[index_key:index_key + len(arguments)] = arguments
-                else:
-                    command_with_arguments[index_key:index_key+1] = []
-            tmp_config.commands = [command_with_arguments]
+    if not isinstance(commands, list) or not len(commands):
+        continue
+    for fixer in _RUNNERS:
+        for i, command in enumerate(commands):
+            fixed_command = fixer.fix(command)
+            if fixed_command:
+                commands[i] = fixed_command
+    tmp_config.commands = commands
 
 session = tox_session.Session(config, Report=_Reporter)
 teamcity.testMatrixEntered()
 
 session = tox_session.Session(config, Report=_Reporter)
 teamcity.testMatrixEntered()