mercredi 6 juillet 2016

Mocking member variable of an object in python

I have the following python code to test

class Foo(object):
    def __init__(self):
        self.__fb_access_tokens = PropertiesReader('path/to/authentication_details/file')
        self.__fb_post_write_path = PropertiesReader('path/to/write_properties/file')

    def write_information(self):
        contents = compute_file_contents()
        write_contents_to_file(self.__fb_post_write_path, contents)

In my testcases I want to mock the self.__fb_post_write_path. I cannot mock PropertiesReader() as it will also effect self.__fb_access_tokens.

Is it possible to mock member variables of an object in python?

Any suggestions would be highly appreciated.

Thanks!

Aucun commentaire:

Enregistrer un commentaire