You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the user uses param() to declare their data, it is possible to know the line number and location of the place where param was called. This information could be memorized by parameterized, and later used to indicate which piece of data caused the failure of the test.
Example
test_number.py:
fromunittestimportTestCasefromparameterizedimportparameterized, paramclassAnimalTestCase(TestCase):
@parameterized.expand( [ # line 8param("inferior", left=1, right=2, inferior=True), # line 9param("equal", left=2, right=2, inferior=True), # line 10param("superior", left=3, right=2, inferior=False), # line 11 ] )deftest_comparison(self, _, left, right, inferior):
self.assertEqual(left<right, inferior)
Currently:
$ python -m unittest test_number.py
.F.
======================================================================
FAIL: test_comparison_1_equal (test_number.NumberTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/mathieucaroff/venv/lib/python3.6/site-packages/parameterized/parameterized.py", line 530, in standalone_func
return func(*(a + p.args), **p.kwargs)
File "/home/mathieucaroff/project/test_number.py", line 15, in test_comparison
self.assertEqual(left < right, inferior)
AssertionError: False != True
----------------------------------------------------------------------
Ran 3 tests in 0.000s
FAILED (failures=1)
There are a number of ways to do it. Here are a few proposals, from the one I like the most to the one I like the least. I'm not sure that all of them can work, but the simplest ones necessarily work.
adding a line in the stack trace
File "/home/mathieucaroff/project/test_number.py", line 15, in test_comparison
self.assertEqual(left < right, inferior)
File "/home/mathieucaroff/project/test_number.py", line 10
param("equal", left=2, right=2, inferior=True), # line 10
AssertionError: False != True
adding the information to the error
File "/home/mathieucaroff/project/test_number.py", line 15, in test_comparison
self.assertEqual(left < right, inferior)
AssertionError: False != True, with data from: "/home/mathieucaroff/project/test_number.py", line 10
adding the information to the name of the generated function
When the user uses
param()
to declare their data, it is possible to know the line number and location of the place whereparam
was called. This information could be memorized by parameterized, and later used to indicate which piece of data caused the failure of the test.Example
test_number.py
:Currently:
There are a number of ways to do it. Here are a few proposals, from the one I like the most to the one I like the least. I'm not sure that all of them can work, but the simplest ones necessarily work.
adding a line in the stack trace
adding the information to the error
adding the information to the name of the generated function
The text was updated successfully, but these errors were encountered: