2010-10-11 06:14:32 +08:00
|
|
|
""" submit failure or test session information to a pastebin service. """
|
2009-08-03 17:56:56 +08:00
|
|
|
import py, sys
|
|
|
|
|
|
|
|
class url:
|
2012-05-08 22:13:25 +08:00
|
|
|
base = "http://bpaste.net"
|
2009-08-03 17:56:56 +08:00
|
|
|
xmlrpc = base + "/xmlrpc/"
|
|
|
|
show = base + "/show/"
|
|
|
|
|
|
|
|
def pytest_addoption(parser):
|
2010-01-03 19:41:29 +08:00
|
|
|
group = parser.getgroup("terminal reporting")
|
2009-08-03 17:56:56 +08:00
|
|
|
group._addoption('--pastebin', metavar="mode",
|
2010-07-27 03:15:15 +08:00
|
|
|
action='store', dest="pastebin", default=None,
|
2013-07-25 21:33:43 +08:00
|
|
|
choices=['failed', 'all'],
|
2012-05-19 16:54:12 +08:00
|
|
|
help="send failed|all info to bpaste.net pastebin service.")
|
2009-08-03 17:56:56 +08:00
|
|
|
|
2009-08-12 01:00:41 +08:00
|
|
|
def pytest_configure(__multicall__, config):
|
2009-08-03 17:56:56 +08:00
|
|
|
import tempfile
|
2009-08-12 01:00:41 +08:00
|
|
|
__multicall__.execute()
|
2009-08-03 17:56:56 +08:00
|
|
|
if config.option.pastebin == "all":
|
2009-09-05 03:47:49 +08:00
|
|
|
config._pastebinfile = tempfile.TemporaryFile('w+')
|
2009-10-17 18:56:59 +08:00
|
|
|
tr = config.pluginmanager.getplugin('terminalreporter')
|
2010-07-27 03:15:15 +08:00
|
|
|
oldwrite = tr._tw.write
|
2009-08-03 17:56:56 +08:00
|
|
|
def tee_write(s, **kwargs):
|
|
|
|
oldwrite(s, **kwargs)
|
|
|
|
config._pastebinfile.write(str(s))
|
2010-07-27 03:15:15 +08:00
|
|
|
tr._tw.write = tee_write
|
2009-08-03 17:56:56 +08:00
|
|
|
|
2010-07-27 03:15:15 +08:00
|
|
|
def pytest_unconfigure(config):
|
2009-08-03 17:56:56 +08:00
|
|
|
if hasattr(config, '_pastebinfile'):
|
|
|
|
config._pastebinfile.seek(0)
|
|
|
|
sessionlog = config._pastebinfile.read()
|
|
|
|
config._pastebinfile.close()
|
|
|
|
del config._pastebinfile
|
|
|
|
proxyid = getproxy().newPaste("python", sessionlog)
|
|
|
|
pastebinurl = "%s%s" % (url.show, proxyid)
|
2009-10-16 05:14:51 +08:00
|
|
|
sys.stderr.write("pastebin session-log: %s\n" % pastebinurl)
|
2009-10-17 18:56:59 +08:00
|
|
|
tr = config.pluginmanager.getplugin('terminalreporter')
|
2009-08-03 17:56:56 +08:00
|
|
|
del tr._tw.__dict__['write']
|
2010-07-27 03:15:15 +08:00
|
|
|
|
2009-08-03 17:56:56 +08:00
|
|
|
def getproxy():
|
2011-11-15 00:51:12 +08:00
|
|
|
if sys.version_info < (3, 0):
|
|
|
|
from xmlrpclib import ServerProxy
|
|
|
|
else:
|
|
|
|
from xmlrpc.client import ServerProxy
|
|
|
|
return ServerProxy(url.xmlrpc).pastes
|
2009-08-03 17:56:56 +08:00
|
|
|
|
|
|
|
def pytest_terminal_summary(terminalreporter):
|
|
|
|
if terminalreporter.config.option.pastebin != "failed":
|
|
|
|
return
|
|
|
|
tr = terminalreporter
|
|
|
|
if 'failed' in tr.stats:
|
|
|
|
terminalreporter.write_sep("=", "Sending information to Paste Service")
|
|
|
|
if tr.config.option.debug:
|
|
|
|
terminalreporter.write_line("xmlrpcurl: %s" %(url.xmlrpc,))
|
|
|
|
serverproxy = getproxy()
|
|
|
|
for rep in terminalreporter.stats.get('failed'):
|
|
|
|
try:
|
|
|
|
msg = rep.longrepr.reprtraceback.reprentries[-1].reprfileloc
|
|
|
|
except AttributeError:
|
|
|
|
msg = tr._getfailureheadline(rep)
|
|
|
|
tw = py.io.TerminalWriter(stringio=True)
|
|
|
|
rep.toterminal(tw)
|
|
|
|
s = tw.stringio.getvalue()
|
|
|
|
assert len(s)
|
|
|
|
proxyid = serverproxy.newPaste("python", s)
|
|
|
|
pastebinurl = "%s%s" % (url.show, proxyid)
|
|
|
|
tr.write_line("%s --> %s" %(msg, pastebinurl))
|