[python, tests] Allow changing verbosity level of unittest test outputs

GitOrigin-RevId: 801c8c054832f3ee6822d0d40b771cf417d0055e
This commit is contained in:
Christoph Thiede
2025-08-19 15:17:26 +00:00
committed by intellij-monorepo-bot
parent 404e120acb
commit 4c857301db
3 changed files with 10 additions and 7 deletions
@@ -18,6 +18,8 @@ if teamcity_presence_env_var not in os.environ:
# 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
# More verbose output of testing framework to aid structured display of output in IDE.
JB_VERBOSE = "JB_VERBOSE" in os.environ
# getcwd resolves symlinks, but PWD is not supported by some shells
PROJECT_DIR = os.getenv('PWD', os.getcwd())
@@ -4,13 +4,15 @@ import sys
from unittest import main
from _jb_runner_tools import jb_start_tests, jb_doc_args, JB_DISABLE_BUFFERING, \
PROJECT_DIR, jb_finish_tests
JB_VERBOSE, PROJECT_DIR, jb_finish_tests
from teamcity import unittestpy
if __name__ == '__main__':
path, targets, additional_args = jb_start_tests()
args = ["python -m unittest"]
args = ["python -m unittest", "--quiet"]
if JB_VERBOSE:
args.append("--verbose") # additional args may override this (unittest argparser works left-to-right)
if path:
assert os.path.exists(path), "{0}: No such file or directory".format(path)
if sys.version_info > (3, 0) and os.path.isfile(path):
@@ -1,6 +1,6 @@
# coding=utf-8
import sys
from unittest import TestResult, TextTestRunner
from unittest import TextTestResult, TextTestRunner
import datetime
import re
@@ -15,12 +15,11 @@ _real_stderr = sys.stderr
_ERROR_HOLDERS_FQN = ("unittest.suite._ErrorHolder", "unittest2.suite._ErrorHolder")
class TeamcityTestResult(TestResult):
class TeamcityTestResult(TextTestResult):
separator2 = "\n"
# noinspection PyUnusedLocal
def __init__(self, stream=_real_stdout, descriptions=None, verbosity=None):
super(TeamcityTestResult, self).__init__()
def __init__(self, stream=_real_stdout, descriptions=None, verbosity=0):
super(TeamcityTestResult, self).__init__(stream, descriptions, verbosity)
# Some code may ask for self.failfast, see unittest2.case.TestCase.subTest
self.failfast = getattr(self, "failfast", False)