samedi 4 novembre 2017

Changing the arguments to Open() using python Mock

I am trying to change the arguments to open() so that my test code will open the files in the test/ directory instead of the original one.

file.py

def testing_opening():
    f = open( 'original/path/to/file', 'r' )
    return f.read()

Now, in my test file, I want to read files from 'test/path/to/file'.

How do I do that? I can mock patch open(), but I don't know how to change it's arguments.

Please help

Aucun commentaire:

Enregistrer un commentaire