Ask Your Question
0

Process dies for test.py with "option --gtest_output not recognized" error

asked 2018-07-06 00:57:52 -0500

130s gravatar image

Running test cases in a subclass of unittest.TestCase via rostest fails with the following error.

rostest pkg_a webbridge.test
... logging to /root/.ros/log/rostest-7748a8fc08fa-7285.log
[ROSUNIT] Outputting test results to /root/.ros/test_results/pkg_a/rostest-test_webbridge.xml
[Testcase: testmodule_a] ... FAILURE!
FAILURE: test [module_a] did not generate test results
  File "/usr/lib/python2.7/unittest/case.py", line 329, in run
    testMethod()
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rostest/runner.py", line 164, in fn
    self.assert_(os.path.isfile(test_file), "test [%s] did not generate test results"%test_name)
  File "/usr/lib/python2.7/unittest/case.py", line 422, in assertTrue
    raise self.failureException(msg)
--------------------------------------------------------------------------------

[ROSTEST]-----------------------------------------------------------------------

[testmodule_a][failed]

SUMMARY
 * RESULT: FAIL
 * TESTS: 0
 * ERRORS: 0
 * FAILURES: 1

ERROR: The following tests failed to run:
 * testmodule_a

rostest log file is in /root/.ros/log/rostest-7748a8fc08fa-7285.log

Only obviously suspicious thing in the log is the following:

[roslaunch][INFO] 2018-07-06 05:07:35,927: ... successfully launched [module_a-2]
[rostest][ERROR] 2018-07-06 05:07:36,282: [module_a-2] process has died [pid 7306, exit code 2, cmd /root/catkin_ws/src/prj_tools/pkg_a/test/src/test_ab.py --gtest_output=xml:/root/.ros/test_results/pkg_a/rosunit-module_a.xml __name:=module_a __log:=/root/.ros/log/7e86be42-80da-11e8-b6ce-0242ac110003/module_a-2.log].
log file: /root/.ros/log/7e86be42-80da-11e8-b6ce-0242ac110003/module_a-2*.log

Digging further:

$ more /root/.ros/log/7e86be42-80da-11e8-b6ce-0242ac110003/module_a-2*.log

option --gtest_output not recognized
Usage: test_ab.py [options] [test] [...]

Options:
  -h, --help       Show this message
  -v, --verbose    Verbose output
  -q, --quiet      Minimal output
  -f, --failfast   Stop on first failure
  -c, --catch      Catch control-C and display results
  -b, --buffer     Buffer stdout and stderr during test runs

Examples:
  test_ab.py                               - run default set of tests
  test_ab.py MyTestSuite                   - run suite 'MyTestSuite'
  test_ab.py MyTestCase.testSomething      - run MyTestCase.testSomething
  test_ab.py MyTestCase                    - run all 'test*' test methods
                                               in MyTestCase

Simplified test case for public view:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest

import rospy
from sensor_msgs.msg import Image
from std_srvs.srv import Trigger

from pkg_a.module_a import ClassA


class TestClassA(unittest.TestCase):

    def setUp(self):
        self._webbridge = ClassA()

    def cb_img(self, data):
        self.assertIsNone(data)

    def test_a(self):
    _srv_name = "srv_a"
        rospy.wait_for_service(_srv_name)
        try:
            _srv_proxy = rospy.ServiceProxy(_srv_name, Trigger)
            _response = _srv_proxy()
        except rospy.ServiceException, e:
            raise e

        # Assertion happens in the callback.
        rospy.Subscriber(_topic_name, Image, self.cb_img)

if __name__ == '__main__':
    unittest.main()
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-07-06 01:01:05 -0500

130s gravatar image

updated 2018-07-06 01:28:59 -0500

Self-answering as I figured it out. Test case file needs to be started by rostest.rosrun like the following code as mentioned in unittest#unittest_code wiki page.

if __name__ == '__main__':
    import rostest
    rostest.rosrun(PKG, 'test_a_node', TestClassA)

Took me a few hours as no direct error output wasn't printed anywhere AFAICT...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-07-06 00:57:52 -0500

Seen: 319 times

Last updated: Jul 06 '18