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

35 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-12 16:26 -0700

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 

8from pkg_resources import iter_entry_points 

9 

10from _jb_runner_tools import jb_patch_separator, jb_doc_args, JB_DISABLE_BUFFERING, \ 

11 start_protocol, parse_arguments, \ 

12 set_parallel_mode, jb_finish_tests 

13from teamcity import pytest_plugin 

14import os 

15 

16if __name__ == '__main__': 

17 path, targets, additional_args = parse_arguments() 

18 sys.argv += additional_args 

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

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

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

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

23 

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

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

26 plugins_to_load = [] 

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

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

29 plugins_to_load.append(pytest_plugin) 

30 

31 args = sys.argv[1:] 

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

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

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

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

36 

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

38 args += ["-s"] 

39 

40 

41 jb_doc_args("pytest", args) 

42 

43 

44 class Plugin: 

45 @staticmethod 

46 def pytest_configure(config): 

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

48 set_parallel_mode() 

49 start_protocol() 

50 

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

52 try: 

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

54 finally: 

55 jb_finish_tests()