status status upper(if status not in self allowed_statusesraise valueerror"{is not valid statusformat(status)key "flightno:{}format(flightvalue "{}|{}formatdatetime datetime now(isoformat()statusself redis set(keyvaluethere are lot of things we ought to test in that change_status method we should check that it raises the appropriate error if bad status is passed in we need to ensure that it converts statuses to uppercase we can see that the key and value have the correct formatting when the set(method is called on the redis object one thing we don' have to check in our unit testshoweveris that the redis object is properly storing the data this is something that absolutely should be tested in integration or application testingbut at the unit test levelwe can assume that the py-redis developers have tested their code and that this method does what we want it to as ruleunit tests should be self-contained and not rely on the existence of outside resourcessuch as running redis instance insteadwe only need to test that the set(method was called the appropriate number of times and with the appropriate arguments we can use mock(objects in our tests to replace the troublesome method with an object we can introspect the following example illustrates the use of mockfrom unittest mock import mock import py test def pytest_funcarg__tracker()return flightstatustracker(def test_mock_method(tracker)tracker redis set mock(with py test raises(valueerroras extracker change_status("ac ""lost"assert ex value args[ ="lost is not valid statusassert tracker redis set call_count =