I'm using pytest to write some unit tests, and wondering what the best approach for testing 'dependent' functions are. Let's say I have two functions:
def set_file(filename, filecontents):
# stores file as key in memcache
def get_file(filename):
# returns the contents of the filename if it exists in cache
Currently, I have a 'happy path' unit test that looks something like this:
def test_happy_path():
assert not get_file('unit test') # check that return of non-existent file is None
set_file('unit test', 'test content') # set file contents
assert get_file('unit test') == 'test content' # check that return matches input
My question is whether this approach is valid? Should I be trying to mock data of set_file when testing get_file to have a unit test that has no dependancies created by set file? If so, how would I mock that, especially since set_file is using pymemcached?
test_happy_pathseems to be valid... - sanyassh