PY-9727: Arguments now copied from tox config
authorIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Fri, 4 Dec 2015 12:57:10 +0000 (15:57 +0300)
committerIlya.Kazakevich <Ilya.Kazakevich@jetbrains.com>
Fri, 4 Dec 2015 12:57:10 +0000 (15:57 +0300)
python/helpers/pycharm/_jb_tox_runner.py

index b1b12bee5b3bde0cb643db5ed9427b29b6935075..2a88022530f53d2ed5d23d248835cfb789435228 100644 (file)
@@ -3,22 +3,26 @@
 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
 """
+import os
 import sys
+
 from tox import config as tox_config, session as tox_session
 from tox.session import Reporter
 
 from tcmessages import TeamcityServiceMessages
-import os
 
 helpers_dir = str(os.path.split(__file__)[0])
 
+# Placeholder to insert arguments
+__ARGUMENTS_KEY = "__jb_place_for_arguments"
+
+
 # List of local runners to use
-_RUNNERS = {"unit2": [os.path.join(helpers_dir, "utrunner.py"), os.getcwd(), "true"]}
+_RUNNERS = {"unit2": [os.path.join(helpers_dir, "utrunner.py"), os.getcwd(), __ARGUMENTS_KEY, "true"]}
 
 teamcity = TeamcityServiceMessages()
 
 
-
 class _Reporter(Reporter):
     def logaction_start(self, action):
         super(_Reporter, self).logaction_start(action)
@@ -31,7 +35,6 @@ class _Reporter(Reporter):
         if action.activity == "runtests":
             teamcity.testSuiteFinished(action.id)
 
-
     def error(self, msg):
         super(_Reporter, self).error(msg)
         name = teamcity.current_test_name()
@@ -49,20 +52,26 @@ class _Reporter(Reporter):
             teamcity.testFinished(name)
 
 
-
-
 config = tox_config.parseconfig()
 for env, tmp_config in config.envconfigs.items():
     if not tmp_config.setenv:
         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) == 1:
+    if isinstance(commands, list) and len(commands):
         command_with_arguments = commands[0]
-        if command_with_arguments[0] in _RUNNERS:
-            command_with_arguments = _RUNNERS[command_with_arguments[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]
 
 session = tox_session.Session(config, Report=_Reporter)
 teamcity.testMatrixEntered()
-session.runcommand()
\ No newline at end of file
+session.runcommand()