Created
June 8, 2012 12:59
-
-
Save hpk42/2895474 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import xmlrpclib | |
import pytest | |
class BugZillaInteg(object): | |
def get_bug_status(self, bugid): | |
"Returns the status of the bug with id bugid" | |
try: | |
bug = self.bugzilla.getbugsimple(bugid) | |
status = str(bug).split(None, 2)[1] | |
print status | |
return status | |
except xmlrpclib.Fault, m: | |
print "Fault received '%s'"% m | |
return "Error" | |
def analysed(self, infostr): | |
"Returns True if bug mentioned in the given docstring exists and is open" | |
if infostr: | |
val = re.search("#([0-9]*)", infostr) | |
if val: | |
bugid = val.groups()[0] | |
status = self.get_bug_status(bugid) | |
if status in ["ASSIGNED", "NEW", "ON_DEV"]: | |
return True | |
else: | |
pass | |
return False | |
@pytest.mark.tryfirst | |
def pytest_report_teststatus(self, report): | |
if report.failed: | |
return "analysed", "A", "ANALYSED" | |
def __init__(self, config, bugzilla): | |
self.config = config | |
self.bugzilla = bugzilla | |
def pytest_addoption(parser): | |
""" | |
Defines the valid options for pytest_bugzilla | |
""" | |
group = parser.getgroup('Bugzilla integration') | |
group.addoption('--bugzilla', action='store_true', default=False, | |
dest='bugzilla', | |
help="Query bugzilla to find to check statuses of bugs mentioned in test docstring") | |
group.addoption("--bugzilla-username", action="store", default = "username", | |
dest = "bugzilla_username", | |
help="Use this username for bugzilla queries") | |
group.addoption("--bugzilla-password", action="store", default = "password", | |
dest = "bugzilla_pw", | |
help="Use this password for bugzilla queries") | |
group.addoption("--bugzilla-url", action="store", default = "https://bugzilla.example.com/xmlrpc.cgi", | |
dest = "bugzilla_url", | |
help="Use this url for bugzilla XML-RPC server") | |
group.addoption("--bugzilla-verbose", action="store_true", default = False, | |
dest = "bugzilla_verbose", | |
help="Enable debugging output for bugzilla plugin (don't use except during plugin development)") | |
def pytest_configure(config): | |
bugzilla_enable = any([config.getvalue("bugzilla"), | |
config.getvalue("bugzilla_username") != "username", | |
config.getvalue("bugzilla_pw") != "password", | |
config.getvalue("bugzilla_url") != "https://bugzilla.example.com/xmlrpc.cgi", | |
config.getvalue("bugzilla_verbose")]) | |
if bugzilla_enable: | |
config.pluginmanager.register(BugZillaInteg(config, None), "bugzilla") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment