Search code examples
pythonequalshamcrestpyhamcrest

Why doesn't PyHamcrest have a negative equality matcher?


Reviewing PyHamcrest's API, I see there's an equal_to matcher

from hamcrest import *
assert_that('1', equal_to('1'))

but there's no parallel negative method such as not_equal_to

from hamcrest import *
assert_that('1', not_equal_to('2'))

What's the proper way of matching negative equality?


Solution

  • The proper way to match for negative equality is to chain the equal_to method with the is_not method

    from hamcrest import *
    assert_that('1', is_not(equal_to('1')))