ApexAI / apex_rostest

Framework for ROS2 Integration Testing
5 stars 6 forks source link

Give more info when output is not in expected sequence #34

Closed pbaughman closed 5 years ago

pbaughman commented 5 years ago

We had a problem with one of our tests where it failed because some of the output was a little out of order occasionally. The test output itself wasn't very helpful to diagnose the problem.

This PR improves the error message you get when you assert that output is sequential. It will print the last line that you matched on, and up to two previous lines and up to two following lines.

Note to Reviewer

The get_nearby_lines method (like the reset of the SequentialTextChecker) is a bit of a mess, but it's well covered with tests. I'm open to better ways to do this, but the way the data is stored behind the scenes isn't super natural for searching backwards and forwards.

You can test this by editing good_proc.test.py. Remove this line and fix up the indentation, then run

apex_launchtest examples/good_proc.test.py and you'll see the new exception output. Right now it looks like this:

======================================================================
FAIL: test_out_of_order (python_launch_file.TestProcessOutput)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/pete.baughman/apex_rostest/apex_launchtest/examples/good_proc.test.py", line 89, in test_out_of_order
    cm.assertInStdout("Loop 2")  # This should raise
  File "/home/pete.baughman/apex_rostest/install/lib/python3.5/site-packages/apex_launchtest/asserts/assert_sequential_output.py", line 58, in assertInStdout
    self.get_nearby_lines()
AssertionError: 'Loop 2' not found in sequence after previous match.  The output near the last matched line:
Loop 1
Loop 2
Loop 3
Loop 4
Shutting Down

Signed-off-by: Pete Baughman pete.baughman@apex.ai

pbaughman commented 5 years ago

This is being migrated in this pr Remove "needs upstream merge" tag once 224 is closed