Created
June 12, 2012 11:29
-
-
Save els-pnw/2916988 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
class BugzillaHooks(object): | |
def __init__(self, config, bugzilla): | |
self.config = config | |
self.bugzilla = bugzilla | |
def pytest_runtest_makereport(self, __multicall__, item): | |
if isinstance(item, item.Function): | |
func = item.obj | |
bugzilla_marker = getattr(func, "bugzilla", None) | |
if bugzilla_marker.args is None: | |
return | |
report = __multicall__.execute() | |
if report.when == 'setup': | |
report.bug_id = bugzilla_marker.args[0] | |
bug = self.bugzilla.getbugsimple(report.bug_id) | |
report.status = str(bug).split(None, 2)[1] | |
return report | |
def pytest_report_teststatus(self, report): | |
bug_id = getattr(report, "bug_id", None) | |
status = getattr(report, "status", None) | |
if bug_id is not None: | |
#if report.failed: | |
# return "failed", "P", "PENDINGFIX" | |
if status in ['NEW', 'ASSIGNED', 'ON_DEV']: | |
return "skipped", "S", "SKIPPED_BUG" | |
def pytest_addoption(parser): | |
""" | |
Add a options section to py.test --help for bugzilla integration. | |
Parse configuration file, bugzilla.cfg and / or the command line options | |
passed. | |
""" | |
config = ConfigParser.ConfigParser() | |
config.read('bugzilla.cfg') | |
group = parser.getgroup('Bugzilla integration') | |
group.addoption('--bugzilla', | |
action='store_true', | |
default=False, | |
dest='bugzilla', | |
help='Enable Bugzilla support.') | |
group.addoption('--bugzilla-url', | |
action='store', | |
dest='bugzilla_url', | |
default=config.get('DEFAULT', 'bugzilla_url'), | |
metavar='url', | |
help='Overrides the xmlrpc url for bugzilla found in bugzilla.cfg.') | |
group.addoption('--bugzilla-user', | |
action='store', | |
dest='bugzilla_username', | |
default=config.get('DEFAULT', 'bugzilla_username'), | |
metavar='username', | |
help='Overrides the bugzilla username in bugzilla.cfg.') | |
group.addoption('--bugzilla-password', | |
action='store', | |
dest='bugzilla_password', | |
default=config.get('DEFAULT', 'bugzilla_password'), | |
metavar='password', | |
help='Overrides the bugzilla password in bugzilla.cfg.') | |
def pytest_configure(config): | |
""" | |
If bugzilla is neabled, setup a session | |
with bugzilla_url. | |
""" | |
if config.getvalue("bugzilla"): | |
url = config.getvalue('bugzilla_url') | |
user = config.getvalue('bugzilla_username') | |
password = config.getvalue('bugzilla_password') | |
bz = bugzilla.Bugzilla(url=url) | |
bz.login(user,password) | |
my = BugzillaHooks(config, bz) | |
ok = config.pluginmanager.register(my, "bugzilla_helper") | |
assert ok |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test_nothin.py S
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/main.py", line 74, in wrap_session
INTERNALERROR> doit(config, session)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/main.py", line 106, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 421, in call
INTERNALERROR> return self._docall(methods, kwargs)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 432, in _docall
INTERNALERROR> res = mc.execute()
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 350, in execute
INTERNALERROR> res = method(**kwargs)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/main.py", line 119, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 421, in call
INTERNALERROR> return self._docall(methods, kwargs)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 432, in _docall
INTERNALERROR> res = mc.execute()
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 350, in execute
INTERNALERROR> res = method(**kwargs)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/runner.py", line 61, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/runner.py", line 68, in runtestprotocol
INTERNALERROR> reports.append(call_and_report(item, "call", log))
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/runner.py", line 99, in call_and_report
INTERNALERROR> report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/main.py", line 141, in call_matching_hooks
INTERNALERROR> return hookmethod.pcall(plugins, **kwargs)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 425, in pcall
INTERNALERROR> return self._docall(methods, kwargs)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 432, in _docall
INTERNALERROR> res = mc.execute()
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/core.py", line 350, in execute
INTERNALERROR> res = method(**kwargs)
INTERNALERROR> File "/usr/lib/python2.7/site-packages/_pytest/capture.py", line 175, in pytest_runtest_makereport
INTERNALERROR> if not rep.passed:
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'passed'
========================== 1 skipped in 1.37 seconds ===========================