0

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( 'file', 'r' )
    return f.read()

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

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

Please help

EDIT: test_file.py

@patch( '__builtin__.open', new_callable=mock_open )
def test_open( m_file ):
    m_file.side_effect = open( os.curdir + '/test/'+ m_file.call_args[0][0], m_file.call_args[1] )
    f = testing_opening()
    print f

0 Answers0