summaryrefslogtreecommitdiff
path: root/python/helpers/pycharm/pytestrunner.py
blob: 0725e2f11ff204a283e71bfa2a2856b775cebf71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys

has_pytest = False
#there is the difference between 1.3.4 and 2.0.2 versions
#Since version 1.4, the testing tool "py.test" is part of its own pytest distribution.
try:
  import pytest
  has_pytest = True
except:
  try:
    import py
  except:
    raise NameError("No py.test runner found in selected interpreter")

def get_plugin_manager():
  try:
    from _pytest.config import get_plugin_manager
    return get_plugin_manager()
  except ImportError:
    from _pytest.core import PluginManager
    return PluginManager(load=True)

if has_pytest:
  _preinit = []
  def main():
    args = sys.argv[1:]
    _pluginmanager = get_plugin_manager()
    hook = _pluginmanager.hook
    try:
      config = hook.pytest_cmdline_parse(
              pluginmanager=_pluginmanager, args=args)
      exitstatus = hook.pytest_cmdline_main(config=config)
    except pytest.UsageError:
      e = sys.exc_info()[1]
      sys.stderr.write("ERROR: %s\n" %(e.args[0],))
      exitstatus = 3
    return exitstatus

else:
  def main():
    args = sys.argv[1:]
    config = py.test.config
    try:
      config.parse(args)
      config.pluginmanager.do_configure(config)
      session = config.initsession()
      colitems = config.getinitialnodes()
      exitstatus = session.main(colitems)
      config.pluginmanager.do_unconfigure(config)
    except config.Error:
      e = sys.exc_info()[1]
      sys.stderr.write("ERROR: %s\n" %(e.args[0],))
      exitstatus = 3
    py.test.config = py.test.config.__class__()
    return exitstatus

if __name__ == "__main__":
  main()