Guest User

Untitled

a guest
Oct 19th, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. import bugzilla
  2. import ConfigParser
  3.  
  4.  
  5. class BugzillaHooks(object):
  6. def __init__(self, config, bugzilla):
  7. self.config = config
  8. self.bugzilla = bugzilla
  9.  
  10. def pytest_runtest_makereport(self, __multicall__, item):
  11.  
  12. if isinstance(item, item.Function):
  13. func = item.obj
  14. bugzilla_marker = getattr(func, "bugzilla", None)
  15. if bugzilla_marker.args is None:
  16. return
  17. report = __multicall__.execute()
  18. if report.when == 'setup':
  19. report.bug_id = bugzilla_marker.args[0]
  20. bug = self.bugzilla.getbugsimple(report.bug_id)
  21. report.status = str(bug).split(None, 2)[1]
  22. return report
  23. else:
  24. return report
  25.  
  26. def pytest_report_teststatus(self, report):
  27. bug_id = getattr(report, "bug_id", None)
  28. status = getattr(report, "status", None)
  29.  
  30. if bug_id is not None:
  31. #if report.failed:
  32. # return "failed", "P", "PENDINGFIX"
  33. if status in ['NEW', 'ASSIGNED', 'ON_DEV']:
  34. return "skipped", "S", "SKIPPED_BUG"
  35. else:
  36. pass
  37.  
  38. def pytest_addoption(parser):
  39. """
  40. Add a options section to py.test --help for bugzilla integration.
  41. Parse configuration file, bugzilla.cfg and / or the command line options
  42. passed.
  43. """
  44.  
  45. config = ConfigParser.ConfigParser()
  46. config.read('bugzilla.cfg')
  47.  
  48. group = parser.getgroup('Bugzilla integration')
  49. group.addoption('--bugzilla',
  50. action='store_true',
  51. default=False,
  52. dest='bugzilla',
  53. help='Enable Bugzilla support.')
  54. group.addoption('--bugzilla-url',
  55. action='store',
  56. dest='bugzilla_url',
  57. default=config.get('DEFAULT', 'bugzilla_url'),
  58. metavar='url',
  59. help='Overrides the xmlrpc url for bugzilla found in bugzilla.cfg.')
  60. group.addoption('--bugzilla-user',
  61. action='store',
  62. dest='bugzilla_username',
  63. default=config.get('DEFAULT', 'bugzilla_username'),
  64. metavar='username',
  65. help='Overrides the bugzilla username in bugzilla.cfg.')
  66. group.addoption('--bugzilla-password',
  67. action='store',
  68. dest='bugzilla_password',
  69. default=config.get('DEFAULT', 'bugzilla_password'),
  70. metavar='password',
  71. help='Overrides the bugzilla password in bugzilla.cfg.')
  72.  
  73. def pytest_configure(config):
  74. """
  75. If bugzilla is neabled, setup a session
  76. with bugzilla_url.
  77. """
  78. if config.getvalue("bugzilla"):
  79. url = config.getvalue('bugzilla_url')
  80. user = config.getvalue('bugzilla_username')
  81. password = config.getvalue('bugzilla_password')
  82.  
  83. bz = bugzilla.Bugzilla(url=url)
  84. bz.login(user,password)
  85.  
  86. my = BugzillaHooks(config, bz)
  87. ok = config.pluginmanager.register(my, "bugzilla_helper")
  88. assert ok
Add Comment
Please, Sign In to add comment