Why doesn't PyHamcrest have a negative equality matcher?

1.1k views Asked by At

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?

1

There are 1 answers

0
noamt On BEST ANSWER

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')))