Coverage for Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm/_jb_pytest_runner.py: 78%

40 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-19 10:04 +0530

1# coding=utf-8 

2 

3# Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. 

4 

5import pytest 

6import sys 

7from _pytest.config import get_plugin_manager 

8import warnings 

9 

10if sys.version_info[:2] >= (3, 10): 

11 from importlib.metadata import entry_points as iter_entry_points 

12else: 

13 with warnings.catch_warnings(): 

14 warnings.simplefilter("ignore", category=DeprecationWarning) 

15 from pkg_resources import iter_entry_points 

16 

17from _jb_runner_tools import jb_patch_separator, jb_doc_args, JB_DISABLE_BUFFERING, \ 

18 start_protocol, parse_arguments, \ 

19 set_parallel_mode, jb_finish_tests 

20from teamcity import pytest_plugin 

21import os 

22 

23if __name__ == '__main__': 

24 path, targets, additional_args = parse_arguments() 

25 sys.argv += additional_args 

26 joined_targets = jb_patch_separator(targets, fs_glue="/", python_glue="::", fs_to_python_glue=".py::") 

27 # When file is launched in pytest it should be file.py: you can't provide it as bare module 

28 joined_targets = [t + ".py" if ":" not in t else t for t in joined_targets] 

29 sys.argv += [path] if path else joined_targets 

30 

31 # plugin is discovered automatically in 3, but not in 2 

32 # to prevent "plugin already registered" problem we check it first 

33 plugins_to_load = [] 

34 if not get_plugin_manager().hasplugin("pytest-teamcity"): 

35 if "pytest-teamcity" not in map(lambda e: e.name, iter_entry_points(group='pytest11', name=None)): 

36 plugins_to_load.append(pytest_plugin) 

37 

38 args = sys.argv[1:] 

39 if "--jb-show-summary" in args: 

40 args.remove("--jb-show-summary") 

41 elif int(pytest.__version__.split('.')[0]) >= 6: 

42 args += ["--no-header", "--no-summary", "-q"] 

43 

44 if JB_DISABLE_BUFFERING and "-s" not in args: 

45 args += ["-s"] 

46 

47 

48 jb_doc_args("pytest", args) 

49 

50 

51 class Plugin: 

52 @staticmethod 

53 def pytest_configure(config): 

54 if getattr(config.option, "numprocesses", None): 

55 set_parallel_mode() 

56 start_protocol() 

57 

58 os.environ["_JB_PPRINT_PRIMITIVES"] = "1" 

59 try: 

60 sys.exit(pytest.main(args, plugins_to_load + [Plugin])) 

61 finally: 

62 jb_finish_tests()