Created
June 12, 2012 11:40
-
-
Save els-pnw/2917035 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 bugzilla | |
import ConfigParser | |
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 | |
else: | |
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" | |
else: | |
pass | |
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 |
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 pytest | |
import os | |
@pytest.mark.skip_selenium | |
@pytest.mark.nondestructive | |
class TestNothin(object): | |
@pytest.mark.bugzilla('824975') | |
def test_new_bz(self): | |
print('hello') | |
assert(os.path.exists('/etc')) | |
@pytest.mark.bugzilla('12345') | |
def test_closed_bz(self): | |
assert(os.path.exists('/etc')) | |
@pytest.mark.bugzilla('12345') | |
def test_closed_bz_with_failure(self): | |
assert(os.path.exists('/etcccc')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment