Skip to content

Commit

Permalink
Add tracebacks to IntegResults. (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwlzn authored May 12, 2018
1 parent a5bb75a commit 9c5d7f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions pex/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import subprocess
import sys
import tempfile
import traceback
from collections import namedtuple
from textwrap import dedent

Expand Down Expand Up @@ -203,11 +204,15 @@ def write_simple_pex(td, exe_contents, dists=None, sources=None, coverage=False)
return pb


class IntegResults(namedtuple('results', 'output return_code exception')):
class IntegResults(namedtuple('results', 'output return_code exception traceback')):
"""Convenience object to return integration run results."""

def assert_success(self):
assert self.exception is None and self.return_code is None
if not (self.exception is None and self.return_code is None):
print(self.traceback)
raise AssertionError('integration test failed: return_code=%s, exception=%r, traceback=%s' % (
self.return_code, self.exception, self.traceback
))

def assert_failure(self):
assert self.exception or self.return_code
Expand All @@ -227,16 +232,20 @@ def mock_logger(msg, v=None):
return mock_logger

exception = None
tb = None
error_code = None
output = []
log.set_logger(logger_callback(output))

try:
main(args=args)
except SystemExit as e:
error_code = e.code
except Exception as e:
exception = e
return IntegResults(output, error_code, exception)
tb = traceback.format_exc()

return IntegResults(output, error_code, exception, tb)


# TODO(wickman) Why not PEX.run?
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ envlist =

[testenv]
commands =
py.test {posargs:-vvs}
py.test {posargs:-vvsx}
# Ensure pex's main entrypoint can be run externally.
pex --cache-dir {envtmpdir}/buildcache wheel requests . -e pex.bin.pex:main --version
deps =
Expand Down

0 comments on commit 9c5d7f3

Please sign in to comment.