test/testing/test_session.py - line 284
| 283 |
| 284 |
| 285 |
| 286 |
| 287 |
| 288 |
| 289 |
| 290 |
| 291 |
| 292 | |
def test_safe_repr(self): |
-> session = self.mainsession(datadir/'brokenrepr.py') |
out = self.file.getvalue() |
print 'Output of simulated "py.test brokenrepr.py":' |
print out |
|
l = session.getitemoutcomepairs(Failed) |
assert len(l) == 2 |
assert out.find("""[Exception("Ha Ha fooled you, I'm a broken repr().") raised in repr()]""" |
assert out.find("[unknown exception raised in repr()]") != -1 | |
test/testing/test_session.py - line 106
| 101 |
| 102 |
| 103 |
| 104 |
| 105 |
| 106 |
| 107 | |
def mainsession(self, *args): |
from py.__.test.terminal.terminal import TerminalSession |
self.file = py.std.StringIO.StringIO() |
config = py.test.config._reparse(list(args)) |
session = TerminalSession(config, file=self.file) |
-> session.main() |
return session | |
test/session.py - line 63
| 55 |
| 56 |
| 57 |
| 58 |
| 59 |
| 60 |
| 61 |
| 62 |
| 63 |
| 64 |
| 65 |
| 66 |
| 67 |
| 68 |
| 69 |
| 70 | |
def main(self): |
""" main loop for running tests. """ |
colitems = self.config.getcolitems() |
try: |
self.header(colitems) |
try: |
try: |
for colitem in colitems: |
-> self.runtraced(colitem) |
except KeyboardInterrupt: |
raise |
finally: |
self.footer(colitems) |
except Exit, ex: |
pass |
return self.getitemoutcomepairs(Failed) | |
test/session.py - line 84
| 72 |
| 73 |
| 74 |
| 75 |
| 76 |
| 77 |
| 78 |
| 79 |
| 80 |
| 81 |
| 82 |
| 83 |
| 84 |
| 85 |
| 86 |
| 87 |
| 88 |
| 89 |
| 90 |
| 91 |
| 92 |
| 93 |
| 94 |
| 95 |
| 96 |
| 97 |
| 98 |
| 99 |
| 100 | |
def runtraced(self, colitem): |
if self.shouldclose(): |
raise Exit, "received external close signal" |
|
outcome = None |
colitem.startcapture() |
try: |
self.start(colitem) |
try: |
try: |
if colitem._stickyfailure: |
raise colitem._stickyfailure |
-> outcome = self.run(colitem) |
except (KeyboardInterrupt, Exit): |
raise |
except Outcome, outcome: |
if outcome.excinfo is None: |
outcome.excinfo = py.code.ExceptionInfo() |
except: |
excinfo = py.code.ExceptionInfo() |
outcome = Failed(excinfo=excinfo) |
assert (outcome is None or |
isinstance(outcome, (list, Outcome))) |
finally: |
self.finish(colitem, outcome) |
if isinstance(outcome, Failed) and self.config.option.exitfirst: |
py.test.exit("exit on first problem configured.", item=colitem) |
finally: |
colitem.finishcapture() | |
test/session.py - line 119
| 102 |
| 103 |
| 104 |
| 105 |
| 106 |
| 107 |
| 108 |
| 109 |
| 110 |
| 111 |
| 112 |
| 113 |
| 114 |
| 115 |
| 116 |
| 117 |
| 118 |
| 119 |
| 120 |
| 121 |
| 122 |
| 123 | |
def run(self, colitem): |
if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): |
return |
if isinstance(colitem, py.test.collect.Item): |
colitem._skipbykeyword(self.config.option.keyword) |
res = colitem.run() |
if res is None: |
return Passed() |
elif not isinstance(res, (list, tuple)): |
raise TypeError("%r.run() returned neither " |
"list, tuple nor None: %r" % (colitem, res)) |
else: |
finish = self.startiteration(colitem, res) |
try: |
for name in res: |
obj = colitem.join(name) |
assert obj is not None |
-> self.runtraced(obj) |
finally: |
if finish: |
finish() |
return res | |
test/session.py - line 84
| 72 |
| 73 |
| 74 |
| 75 |
| 76 |
| 77 |
| 78 |
| 79 |
| 80 |
| 81 |
| 82 |
| 83 |
| 84 |
| 85 |
| 86 |
| 87 |
| 88 |
| 89 |
| 90 |
| 91 |
| 92 |
| 93 |
| 94 |
| 95 |
| 96 |
| 97 |
| 98 |
| 99 |
| 100 | |
def runtraced(self, colitem): |
if self.shouldclose(): |
raise Exit, "received external close signal" |
|
outcome = None |
colitem.startcapture() |
try: |
self.start(colitem) |
try: |
try: |
if colitem._stickyfailure: |
raise colitem._stickyfailure |
-> outcome = self.run(colitem) |
except (KeyboardInterrupt, Exit): |
raise |
except Outcome, outcome: |
if outcome.excinfo is None: |
outcome.excinfo = py.code.ExceptionInfo() |
except: |
excinfo = py.code.ExceptionInfo() |
outcome = Failed(excinfo=excinfo) |
assert (outcome is None or |
isinstance(outcome, (list, Outcome))) |
finally: |
self.finish(colitem, outcome) |
if isinstance(outcome, Failed) and self.config.option.exitfirst: |
py.test.exit("exit on first problem configured.", item=colitem) |
finally: |
colitem.finishcapture() | |
test/session.py - line 119
| 102 |
| 103 |
| 104 |
| 105 |
| 106 |
| 107 |
| 108 |
| 109 |
| 110 |
| 111 |
| 112 |
| 113 |
| 114 |
| 115 |
| 116 |
| 117 |
| 118 |
| 119 |
| 120 |
| 121 |
| 122 |
| 123 | |
def run(self, colitem): |
if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): |
return |
if isinstance(colitem, py.test.collect.Item): |
colitem._skipbykeyword(self.config.option.keyword) |
res = colitem.run() |
if res is None: |
return Passed() |
elif not isinstance(res, (list, tuple)): |
raise TypeError("%r.run() returned neither " |
"list, tuple nor None: %r" % (colitem, res)) |
else: |
finish = self.startiteration(colitem, res) |
try: |
for name in res: |
obj = colitem.join(name) |
assert obj is not None |
-> self.runtraced(obj) |
finally: |
if finish: |
finish() |
return res | |
test/session.py - line 84
| 72 |
| 73 |
| 74 |
| 75 |
| 76 |
| 77 |
| 78 |
| 79 |
| 80 |
| 81 |
| 82 |
| 83 |
| 84 |
| 85 |
| 86 |
| 87 |
| 88 |
| 89 |
| 90 |
| 91 |
| 92 |
| 93 |
| 94 |
| 95 |
| 96 |
| 97 |
| 98 |
| 99 |
| 100 | |
def runtraced(self, colitem): |
if self.shouldclose(): |
raise Exit, "received external close signal" |
|
outcome = None |
colitem.startcapture() |
try: |
self.start(colitem) |
try: |
try: |
if colitem._stickyfailure: |
raise colitem._stickyfailure |
-> outcome = self.run(colitem) |
except (KeyboardInterrupt, Exit): |
raise |
except Outcome, outcome: |
if outcome.excinfo is None: |
outcome.excinfo = py.code.ExceptionInfo() |
except: |
excinfo = py.code.ExceptionInfo() |
outcome = Failed(excinfo=excinfo) |
assert (outcome is None or |
isinstance(outcome, (list, Outcome))) |
finally: |
self.finish(colitem, outcome) |
if isinstance(outcome, Failed) and self.config.option.exitfirst: |
py.test.exit("exit on first problem configured.", item=colitem) |
finally: |
colitem.finishcapture() | |
test/session.py - line 119
| 102 |
| 103 |
| 104 |
| 105 |
| 106 |
| 107 |
| 108 |
| 109 |
| 110 |
| 111 |
| 112 |
| 113 |
| 114 |
| 115 |
| 116 |
| 117 |
| 118 |
| 119 |
| 120 |
| 121 |
| 122 |
| 123 | |
def run(self, colitem): |
if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): |
return |
if isinstance(colitem, py.test.collect.Item): |
colitem._skipbykeyword(self.config.option.keyword) |
res = colitem.run() |
if res is None: |
return Passed() |
elif not isinstance(res, (list, tuple)): |
raise TypeError("%r.run() returned neither " |
"list, tuple nor None: %r" % (colitem, res)) |
else: |
finish = self.startiteration(colitem, res) |
try: |
for name in res: |
obj = colitem.join(name) |
assert obj is not None |
-> self.runtraced(obj) |
finally: |
if finish: |
finish() |
return res | |
test/session.py - line 84
| 72 |
| 73 |
| 74 |
| 75 |
| 76 |
| 77 |
| 78 |
| 79 |
| 80 |
| 81 |
| 82 |
| 83 |
| 84 |
| 85 |
| 86 |
| 87 |
| 88 |
| 89 |
| 90 |
| 91 |
| 92 |
| 93 |
| 94 |
| 95 |
| 96 |
| 97 |
| 98 |
| 99 |
| 100 | |
def runtraced(self, colitem): |
if self.shouldclose(): |
raise Exit, "received external close signal" |
|
outcome = None |
colitem.startcapture() |
try: |
self.start(colitem) |
try: |
try: |
if colitem._stickyfailure: |
raise colitem._stickyfailure |
-> outcome = self.run(colitem) |
except (KeyboardInterrupt, Exit): |
raise |
except Outcome, outcome: |
if outcome.excinfo is None: |
outcome.excinfo = py.code.ExceptionInfo() |
except: |
excinfo = py.code.ExceptionInfo() |
outcome = Failed(excinfo=excinfo) |
assert (outcome is None or |
isinstance(outcome, (list, Outcome))) |
finally: |
self.finish(colitem, outcome) |
if isinstance(outcome, Failed) and self.config.option.exitfirst: |
py.test.exit("exit on first problem configured.", item=colitem) |
finally: |
colitem.finishcapture() | |
test/session.py - line 107
| 102 |
| 103 |
| 104 |
| 105 |
| 106 |
| 107 |
| 108 |
| 109 |
| 110 |
| 111 |
| 112 |
| 113 |
| 114 |
| 115 |
| 116 |
| 117 |
| 118 |
| 119 |
| 120 |
| 121 |
| 122 |
| 123 | |
def run(self, colitem): |
if self.config.option.collectonly and isinstance(colitem, py.test.collect.Item): |
return |
if isinstance(colitem, py.test.collect.Item): |
colitem._skipbykeyword(self.config.option.keyword) |
-> res = colitem.run() |
if res is None: |
return Passed() |
elif not isinstance(res, (list, tuple)): |
raise TypeError("%r.run() returned neither " |
"list, tuple nor None: %r" % (colitem, res)) |
else: |
finish = self.startiteration(colitem, res) |
try: |
for name in res: |
obj = colitem.join(name) |
assert obj is not None |
self.runtraced(obj) |
finally: |
if finish: |
finish() |
return res | |
test/item.py - line 64
|
|
def run(self): |
""" setup and execute the underlying test function. """ |
self._state.prepare(self) |
-> self.execute(self.obj, *self._args) | |
test/item.py - line 68
|
|
def execute(self, target, *args): |
""" execute the given test function. """ |
-> target(*args) | |
/tmp/pytest-1/datadir/brokenrepr.py - line 28
|
|
def test_implicit_bad_repr1(self): |
t = BrokenRepr1() |
-> assert t.foo == 1 | |
magic/assertion.py - line 22
| 8 |
| 9 |
| 10 |
| 11 |
| 12 |
| 13 |
| 14 |
| 15 |
| 16 |
| 17 |
| 18 |
| 19 |
| 20 |
| 21 |
| 22 |
| 23 |
| 24 |
| 25 |
| 26 | |
def __init__(self, *args): |
BuiltinAssertionError.__init__(self, *args) |
if args: |
self.msg = str(args[0]) |
else: |
f = sys._getframe(1) |
try: |
source = py.code.Frame(f).statement |
source = str(source.deindent()).strip() |
except py.error.ENOENT: |
source = None |
|
|
if source: |
-> self.msg = exprinfo.interpret(source, f, should_fail=True) |
if not self.args: |
self.args = (self.msg,) |
else: |
self.msg = None | |
magic/exprinfo.py - line 417
| 416 |
| 417 |
| 418 |
| 419 |
| 420 |
| 421 |
| 422 |
| 423 |
| 424 |
| 425 |
| 426 |
| 427 |
| 428 |
| 429 |
| 430 |
| 431 |
| 432 |
| 433 | |
def interpret(source, frame, should_fail=False): |
-> module = Interpretable(parse(source, 'exec').node) |
|
if isinstance(frame, py.std.types.FrameType): |
frame = py.code.Frame(frame) |
try: |
module.run(frame) |
except Failure, e: |
return getfailure(e) |
except passthroughex: |
raise |
except: |
import traceback |
traceback.print_exc() |
if should_fail: |
return "(inconsistently failed then succeeded)" |
else: |
return None | |
/usr/lib/python2.6/compiler/transformer.py - line 51
|
|
def parse(buf, mode="exec"): |
if mode == "exec" or mode == "single": |
-> return Transformer().parsesuite(buf) |
elif mode == "eval": |
return Transformer().parseexpr(buf) |
else: |
raise ValueError("compile() arg 3 must be" |
" 'exec' or 'eval' or 'single'") | |
/usr/lib/python2.6/compiler/transformer.py - line 106
| 104 |
| 105 |
| 106 |
| 107 |
| 108 |
| 109 |
| 110 |
| 111 |
| 112 |
| 113 |
| 114 |
| 115 |
| 116 |
| 117 |
| 118 | |
def __init__(self): |
self._dispatch = {} |
-> for value, name in symbol.sym_name.items(): |
if hasattr(self, name): |
self._dispatch[value] = getattr(self, name) |
self._dispatch[token.NEWLINE] = self.com_NEWLINE |
self._atom_dispatch = {token.LPAR: self.atom_lpar, |
token.LSQB: self.atom_lsqb, |
token.LBRACE: self.atom_lbrace, |
token.BACKQUOTE: self.atom_backquote, |
token.NUMBER: self.atom_number, |
token.STRING: self.atom_string, |
token.NAME: self.atom_name, |
} |
self.encoding = None | |