diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-05-21 13:06:36 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-05-21 13:06:36 -0400 |
commit | 791b226666149e3074f1046fa5e51f2c7386f800 (patch) | |
tree | 39880f69fdc3c34fb6abb86f48c8d0215b396911 /cmd2/cmd2.py | |
parent | 2f0dbf5bad19d96880e2ef795660db1b8f04cdc7 (diff) | |
download | cmd2-git-791b226666149e3074f1046fa5e51f2c7386f800.tar.gz |
Modified transcript testing so that the useless exception trackeback isn't printed in failure cases
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index f54a0652..9d36e1b4 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -3683,12 +3683,23 @@ class Cmd(cmd.Cmd): self.__class__.testfiles = callargs sys.argv = [sys.argv[0]] # the --test argument upsets unittest.main() testcase = TestMyAppCase() - runner = unittest.TextTestRunner() + stream = utils.StdSim(sys.stderr) + runner = unittest.TextTestRunner(stream=stream) test_results = runner.run(testcase) if test_results.wasSuccessful(): + self.decolorized_write(sys.stderr, stream.read()) self.poutput('Tests passed', color=Fore.LIGHTGREEN_EX) else: - self.perror('Tests failed', traceback_war=False) + # Strip off the initial trackeback which isn't particularly useful for end users + error_str = stream.read() + end_of_trace = error_str.find('AssertionError:') + file_offset = error_str[end_of_trace:].find('File ') + start = end_of_trace + file_offset + + # But print the transcript file name and line number followed by what was expected and what was observed + self.perror(error_str[start:], traceback_war=False) + + # Return a failure error code to support automated transcript-based testing self.exit_code = -1 def async_alert(self, alert_msg: str, new_prompt: Optional[str] = None) -> None: # pragma: no cover |