Search code examples
pythonunit-testingassertnose

Can Python nose tests show wrong value?


I'm running some tests with nose, and it works fine, but in the result, I only see which test on which line failed, not what the wrong value was. For example, I'm running nosetests -v and I get this:

======================================================================
FAIL: tests.test_convert_to_steer
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/pi/ared/tests.py", line 7, in test_convert_to_steer
    assert convert_to_steer(100, 100) == 100
AssertionError

This only tells me which tests failed, but I now have to manually print out the result of convert_to_steer(100, 100) to see what the result was.

Does anybody know how it can also give me what the result was on which I get an error?


Solution

  • If your test suite extends unittest.TestCase, you can use self.assertEqual(convert_to_steer(100, 100), 100).

    For more information, see the docs.