#1940·testify

Add ErrorNotContains assertion

Author: mmorel-35Created Aug 21, 2026Updated Aug 22, 2026
Labelsenhancement

I'd like to propose adding the counterpart of "ErrorContains".

Today we can write:

require.ErrorContains(t, err, "/my/new/path")

instead of:

require.Contains(t, err.Error(), "/my/new/path")

However, there is no equivalent for the negative case, so we still have to write:

require.Error(t, err) require.NotContains(t, err.Error(), "a/b/c")

Would you consider adding something like "ErrorNotContains" (or "NotErrorContains")?

The idea would be to assert that:

  • "err" is not "nil"
  • "err.Error()" does not contain the given substring

It would make the API more symmetric with "ErrorContains" and avoid having to call "err.Error()" directly.

It would also allow tools such as testifylint to safely simplify the pattern above without losing the err != nil assertion.