Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. import sys
  2. import os
  3.  
  4. helpers_dir = os.getenv("PYCHARM_HELPERS_DIR", sys.path[0])
  5. if sys.path[0] != helpers_dir:
  6. sys.path.insert(0, helpers_dir)
  7.  
  8. from nose_utils import TeamcityPlugin
  9.  
  10. from pycharm_run_utils import debug, import_system_module
  11. from pycharm_run_utils import adjust_sys_path
  12.  
  13. adjust_sys_path(False)
  14.  
  15. shlex = import_system_module("shlex")
  16.  
  17. try:
  18. from nose import run_exit
  19. from nose.core import TestProgram
  20. from nose.config import Config
  21. from nose.plugins.manager import DefaultPluginManager
  22. except:
  23. raise NameError("Please, install nosetests")
  24.  
  25. teamcity_plugin = TeamcityPlugin()
  26.  
  27. class MyConfig(Config):
  28. def __init__(self, **kw):
  29. super(MyConfig, self).__init__(**kw)
  30.  
  31. def __setstate__(self, state):
  32. super(MyConfig, self).__setstate__(state)
  33. self.plugins.addPlugin(teamcity_plugin)
  34.  
  35. def process_args():
  36. tests = []
  37.  
  38. opts = None
  39. if sys.argv[-1].startswith("-"):
  40. test_names = sys.argv[1:-1]
  41. opts = sys.argv[-1]
  42. else:
  43. test_names = sys.argv[1:]
  44.  
  45. for arg in test_names:
  46. arg = arg.strip()
  47. if len(arg) == 0:
  48. return
  49.  
  50. a = arg.split("::")
  51. if len(a) == 1:
  52. # From module or folder
  53. a_splitted = a[0].split(";")
  54. if len(a_splitted) != 1:
  55. # means we have pattern to match against
  56. if a_splitted[0].endswith("/"):
  57. debug("/ from folder " + a_splitted[0] + ". Use pattern: " + a_splitted[1])
  58. tests.append(a_splitted[0])
  59. else:
  60. if a[0].endswith("/"):
  61. debug("/ from folder " + a[0])
  62. tests.append(a[0])
  63. else:
  64. debug("/ from module " + a[0])
  65. tests.append(a[0])
  66.  
  67. elif len(a) == 2:
  68. # From testcase
  69. debug("/ from testcase " + a[1] + " in " + a[0])
  70. tests.append(a[0] + ":" + a[1])
  71. else:
  72. # From method in class or from function
  73. debug("/ from method " + a[2] + " in testcase " + a[1] + " in " + a[0])
  74. if a[1] == "":
  75. # test function, not method
  76. tests.append(a[0] + ":" + a[2])
  77. else:
  78. tests.append(a[0] + ":" + a[1] + "." + a[2])
  79.  
  80. argv = ['nosetests']
  81.  
  82. argv.extend(tests)
  83.  
  84.  
  85. if opts:
  86. options = shlex.split(opts)
  87. argv.extend(options)
  88.  
  89. # manager = DefaultPluginManager()
  90. # manager.addPlugin(teamcity_plugin)
  91. # config = MyConfig(plugins=manager)
  92. # config.configure(argv)
  93.  
  94. TestProgram(argv=argv, config=None, exit=False, addplugins=[teamcity_plugin])
  95.  
  96. if __name__ == "__main__":
  97. process_args()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement