Are there sanity check assertions? #10598
-
If I want to assert that something is working correctly within the context of my tests, rather than something working correctly in the context of the code that I'm testing, is there a special way to make that sort assertion? An example. I wish to check that an image is being resized with "inter-area" interpolation for smaller-than-1 resize factors, and "bicubic" interpolation for 1-or-larger resize factors. I could write my test function like: def test():
image = # a blank image
assert(resize_with_auto_interpolation(image, factor=2) == resize(image, factor=2, interpolation='bicubic')
assert(resize_with_auto_interpolation(image, factor=0.5) == resize(image, factor50.4, interpolation='inter-area') But this is a bad test because a blank image would give the same result either way. Now a better way might be: def test():
image = # an image with horizontal stripes
assert(resize_with_auto_interpolation(image, factor=2) == resize(image, factor=2, interpolation='bicubic')
assert(resize_with_auto_interpolation(image, factor=0.5) == resize(image, factor50.4, interpolation='inter-area') Which might work but it's not obvious that it definitely will. The developer should check that it does. They can check manually and write a comment saying that they checked. Or better, they can do sanity checks: def test():
image = # an image with horizontal stripes
assert(resize_with_auto_interpolation(image, factor=2) == resize(image, factor=2, interpolation='bicubic')
assert(resize_with_auto_interpolation(image, factor=0.5) == resize(image, factor50.4, interpolation='inter-area')
# Sanity checks
assert(resize_with_auto_interpolation(image, factor=2) != resize(image, factor=2, interpolation='inter-area')
assert(resize_with_auto_interpolation(image, factor=0.5) != resize(image, factor50.4, interpolation='bicubic') But the sanity checks are a test for the test. They are not a test for the library code. Is there a way to distinguish between the two types of assertions? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
its unclear what you are asking for, please give a example |
Beta Was this translation helpful? Give feedback.
-
there currently is no direct way to distinguish those, i would recommend the subtest extension to split the reporting |
Beta Was this translation helpful? Give feedback.
there currently is no direct way to distinguish those, i would recommend the subtest extension to split the reporting