Guest User

Untitled

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