1import sys
2sys.stderr.write("Warning: You are using test runners in legacy mode\n. "
3                 "That means you have 'python.tests.enableUniversalTests=false' in registry.\n"
4                 "This mode will be dropped in 2021. Consider removing this entry from registry and migrating to new test runners")
5has_pytest = False
6#there is the difference between 1.3.4 and 2.0.2 versions
7#Since version 1.4, the testing tool "py.test" is part of its own pytest distribution.
8try:
9  import pytest
10  has_pytest = True
11except:
12  try:
13    import py
14  except:
15    raise NameError("No pytest runner found in selected interpreter")
16
17def get_plugin_manager():
18  try:
19    from _pytest.config import get_plugin_manager
20    return get_plugin_manager()
21  except ImportError:
22    from _pytest.core import PluginManager
23    return PluginManager(load=True)
24
25# "-s" is always required: no test output provided otherwise (see PY-12621)
26args = sys.argv[1:]
27args.append("-s") if "-s" not in args else None
28
29if has_pytest:
30  _preinit = []
31  def main():
32    _pluginmanager = get_plugin_manager()
33    hook = _pluginmanager.hook
34    try:
35      config = hook.pytest_cmdline_parse(
36              pluginmanager=_pluginmanager, args=args)
37      exitstatus = hook.pytest_cmdline_main(config=config)
38    except pytest.UsageError:
39      e = sys.exc_info()[1]
40      sys.stderr.write("ERROR: %s\n" %(e.args[0],))
41      exitstatus = 3
42    return exitstatus
43
44else:
45  def main():
46    config = py.test.config
47    try:
48      config.parse(args)
49      config.pluginmanager.do_configure(config)
50      session = config.initsession()
51      colitems = config.getinitialnodes()
52      exitstatus = session.main(colitems)
53      config.pluginmanager.do_unconfigure(config)
54    except config.Error:
55      e = sys.exc_info()[1]
56      sys.stderr.write("ERROR: %s\n" %(e.args[0],))
57      exitstatus = 3
58    py.test.config = py.test.config.__class__()
59    return exitstatus
60
61if __name__ == "__main__":
62  main()
63