testify
testify copied to clipboard
Prepend key name to assert.InDeltaMapValues error message
currently the message isn't too helpful, it shows the values that are wrong but does not say which key that value belongs to. Currently test code
assert.InDeltaMapValues(t, map[string]int{"a": 3, "b": 1}, map[string]int{"a": 4, "b": 1}, 0.01)
will just produce
t_test.go:7:
Error Trace: /tmp/a/t_test.go:7
Error: Max difference between 3 and 4 allowed is 0.01, but difference was -1
Test: TestT
with no indication which value is wrong
I did try to write a patch for it and it does work
https://github.com/efigence/testify/tree/key-name-map-value
--- FAIL: TestT (0.00s)
t_test.go:7:
Error Trace: /tmp/a/t_test.go:7
Error: key["a"]: Max difference between 3 and 4 allowed is 0.01, but difference was -1
Test: TestT
but it is hacky at best, I wanted to avoid duplicating InDelta but I haven't found a good way to do it