Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assert `is` in python unittest [duplicate]

What is the best way to do assertEqual with unittest in Python, but instead of testing == it tests is? I want to ensure I have the same object, not just objects that compare equal. This is important, because some of the objects I'm working with are heap types with wacky compare operators.

like image 576
Elliot Gorokhovsky Avatar asked Sep 02 '26 11:09

Elliot Gorokhovsky


2 Answers

That would be the assertIs method.

like image 62
Ry- Avatar answered Sep 04 '26 00:09

Ry-


Use assertIs which does exactly what you want.

https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertIs

like image 38
Amber Avatar answered Sep 04 '26 02:09

Amber