diff --git a/python/helpers/pycharm/_jb_nosetest_runner.py b/python/helpers/pycharm/_jb_nosetest_runner.py index 51e318fc27d4..994e6bff37ee 100644 --- a/python/helpers/pycharm/_jb_nosetest_runner.py +++ b/python/helpers/pycharm/_jb_nosetest_runner.py @@ -4,12 +4,14 @@ import re import nose import sys -from _jb_runner_tools import jb_start_tests, jb_patch_separator, jb_doc_args +from _jb_runner_tools import jb_start_tests, jb_patch_separator, jb_doc_args, JB_DISABLE_BUFFERING from teamcity.nose_report import TeamcityReport if __name__ == '__main__': path, targets, additional_args = jb_start_tests() sys.argv += [path] if path else jb_patch_separator(targets, fs_glue="/", python_glue=".", fs_to_python_glue=".py:") sys.argv += additional_args + if JB_DISABLE_BUFFERING and "-s" not in sys.argv: + sys.argv += ["-s"] jb_doc_args("Nosetest", sys.argv) nose.main(addplugins=[TeamcityReport()]) diff --git a/python/helpers/pycharm/_jb_pytest_runner.py b/python/helpers/pycharm/_jb_pytest_runner.py index 18ca4cd3030b..61f657f356c7 100644 --- a/python/helpers/pycharm/_jb_pytest_runner.py +++ b/python/helpers/pycharm/_jb_pytest_runner.py @@ -5,7 +5,7 @@ import sys import pytest from _pytest.config import get_plugin_manager -from _jb_runner_tools import jb_start_tests, jb_patch_separator, jb_doc_args +from _jb_runner_tools import jb_start_tests, jb_patch_separator, jb_doc_args, JB_DISABLE_BUFFERING from teamcity import pytest_plugin @@ -17,11 +17,15 @@ if __name__ == '__main__': # When file is launched in py.test it should be file.py: you can't provide it as bare module joined_targets = [t + ".py" if ":" not in t else t for t in joined_targets] sys.argv += [path] if path else joined_targets - jb_doc_args("py.test", sys.argv[1:]) # plugin is discovered automatically in 3, but not in 2 # to prevent "plugin already registered" problem we check it first plugins_to_load = [] if not get_plugin_manager().hasplugin("pytest-teamcity"): plugins_to_load.append(pytest_plugin) - pytest.main(sys.argv[1:], plugins_to_load) + + args = sys.argv[1:] + if JB_DISABLE_BUFFERING and "-s" not in args: + args += ["-s"] + jb_doc_args("py.test", args) + pytest.main(args, plugins_to_load) diff --git a/python/helpers/pycharm/_jb_runner_tools.py b/python/helpers/pycharm/_jb_runner_tools.py index 82a396bc586e..7bff640d5beb 100644 --- a/python/helpers/pycharm/_jb_runner_tools.py +++ b/python/helpers/pycharm/_jb_runner_tools.py @@ -14,6 +14,11 @@ from teamcity import teamcity_presence_env_var, messages if teamcity_presence_env_var not in os.environ: os.environ[teamcity_presence_env_var] = "LOCAL" +# Providing this env variable disables output buffering. +# anything sent to stdout/stderr goes to IDE directly, not after test is over like it is done by default. +# out and err are not in sync, so output may go to wrong test +JB_DISABLE_BUFFERING = "JB_DISABLE_BUFFERING" in os.environ + def _parse_parametrized(part): """ diff --git a/python/helpers/pycharm/_jb_unittest_runner.py b/python/helpers/pycharm/_jb_unittest_runner.py index 9ca46b4d00c8..369b434329e1 100644 --- a/python/helpers/pycharm/_jb_unittest_runner.py +++ b/python/helpers/pycharm/_jb_unittest_runner.py @@ -3,7 +3,7 @@ import os import sys from unittest import main -from _jb_runner_tools import jb_start_tests, jb_doc_args +from _jb_runner_tools import jb_start_tests, jb_doc_args, JB_DISABLE_BUFFERING from teamcity import unittestpy if __name__ == '__main__': @@ -32,4 +32,4 @@ if __name__ == '__main__': jb_doc_args("unittests", args) # Working dir should be on path, that is how unittest work when launched from command line sys.path.append(os.getcwd()) - main(argv=args, module=None, testRunner=unittestpy.TeamcityTestRunner, buffer=True) + main(argv=args, module=None, testRunner=unittestpy.TeamcityTestRunner, buffer=not JB_DISABLE_BUFFERING)