I have the following code that I'm testing.
main.py
import helpers
def do_something(some_arg):
...
return helpers.help_do_something(some_arg)
test_main.py
import unittest
from unittest import mock
class TestDoSomething(unittest.Testcase):
@mock.patch('path.to.patch')
def setUp(self, *_):
import main
self.main = main
@mock.patch('main.helpers')
def test_0_1(self, helpers_mock):
ret = self.main.do_something('test_arg')
self.assertIs(ret, helpers_mock.help_do_something.return_value)
When I'm testing the return value of do_something
my instinct is telling me that the comparison should be asserting object equality, not value equality. Am I correct in thinking this? I'm having a difficult time articulating why this should be the case.
More generally, when should we be testing for object equality versus value equality in unit testing?