mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-85040 fix --quiet being passed to unittest before discover
(cherry picked from commit 0d100a2b07af6defab9c1fa841f309a652a6e4dd) IJ-MR-182152 GitOrigin-RevId: 9dddc0484a9fa1527c362fbd6ed90c3fa38d271d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6919d77e99
commit
f92798bb47
@@ -1,43 +1,87 @@
|
||||
# coding=utf-8
|
||||
import errno
|
||||
import os
|
||||
import sys
|
||||
from unittest import main
|
||||
from unittest import main as unittest_main
|
||||
|
||||
from _jb_runner_tools import jb_start_tests, jb_doc_args, JB_DISABLE_BUFFERING, \
|
||||
JB_VERBOSE, PROJECT_DIR, jb_finish_tests
|
||||
from _jb_runner_tools import JB_DISABLE_BUFFERING
|
||||
from _jb_runner_tools import JB_VERBOSE
|
||||
from _jb_runner_tools import PROJECT_DIR
|
||||
from _jb_runner_tools import jb_doc_args
|
||||
from _jb_runner_tools import jb_finish_tests
|
||||
from _jb_runner_tools import jb_start_tests
|
||||
from teamcity import unittestpy
|
||||
|
||||
if __name__ == '__main__':
|
||||
path, targets, additional_args = jb_start_tests()
|
||||
|
||||
args = ["python -m unittest", "--quiet"]
|
||||
if JB_VERBOSE:
|
||||
args.append("--verbose") # additional args may override this (unittest argparser works left-to-right)
|
||||
def build_unittest_args(
|
||||
path,
|
||||
targets,
|
||||
additional_args,
|
||||
project_dir=PROJECT_DIR,
|
||||
verbose=JB_VERBOSE,
|
||||
):
|
||||
args = ["python -m unittest"]
|
||||
subcommand_args = []
|
||||
|
||||
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):
|
||||
# In Py3 it is possible to run script directly which is much more stable than discovery machinery
|
||||
# For example it supports hyphens in file names PY-23549
|
||||
additional_args = [path] + additional_args
|
||||
if not os.path.exists(path):
|
||||
raise OSError(errno.ENOENT, "No such file or directory", path)
|
||||
|
||||
if sys.version_info >= (3, 0) and os.path.isfile(path):
|
||||
# in Py3 it is possible to run script directly
|
||||
# which is much more stable than discovery machinery
|
||||
# for example it supports hyphens in file names PY-23549
|
||||
subcommand_args = [path]
|
||||
else:
|
||||
discovery_args = ["discover", "-s"]
|
||||
# Unittest in py2 does not support running script directly (and folders in py2 and py3),
|
||||
# but it can use "discover" to find all tests in some folder (optionally filtering by script)
|
||||
subcommand_args = ["discover", "-s"]
|
||||
|
||||
# unittest in py2 does not support running script directly
|
||||
# (and folders in py2 and py3),
|
||||
# but it can use "discover" to find all tests in some folder
|
||||
# (optionally filtering by script)
|
||||
if os.path.isfile(path):
|
||||
discovery_args += [os.path.dirname(path), "-p", os.path.basename(path)]
|
||||
subcommand_args += [
|
||||
os.path.dirname(path),
|
||||
"-p",
|
||||
os.path.basename(path)
|
||||
]
|
||||
else:
|
||||
discovery_args.append(path)
|
||||
discovery_args += ["-t",
|
||||
PROJECT_DIR] # To force unit calculate path relative to this folder
|
||||
additional_args = discovery_args + additional_args
|
||||
subcommand_args.append(path)
|
||||
|
||||
# to force unittest to calculate the path relative to this folder
|
||||
subcommand_args += ["-t", project_dir]
|
||||
elif targets:
|
||||
additional_args += targets
|
||||
subcommand_args = list(targets)
|
||||
|
||||
args += subcommand_args
|
||||
|
||||
if verbose:
|
||||
args.append("--verbose")
|
||||
else:
|
||||
args.append("--quiet")
|
||||
|
||||
args += additional_args
|
||||
return args
|
||||
|
||||
|
||||
def main():
|
||||
path, targets, additional_args = jb_start_tests()
|
||||
args = build_unittest_args(path, targets, additional_args)
|
||||
jb_doc_args("unittests", args)
|
||||
# Working dir should be on path, that is how unittest work when launched from command line
|
||||
|
||||
# working dir should be on path
|
||||
# that is how unittest work when launched from command line
|
||||
sys.path.insert(0, PROJECT_DIR)
|
||||
|
||||
try:
|
||||
sys.exit(main(argv=args, module=None, testRunner=unittestpy.TeamcityTestRunner,
|
||||
buffer=not JB_DISABLE_BUFFERING))
|
||||
sys.exit(unittest_main(
|
||||
argv=args,
|
||||
module=None,
|
||||
testRunner=unittestpy.TeamcityTestRunner,
|
||||
buffer=not JB_DISABLE_BUFFERING
|
||||
))
|
||||
finally:
|
||||
jb_finish_tests()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user