mercredi 6 avril 2016

Substituting a variable in a test (using mock? or otherwise) in Python

I have a function that puts some sql into a dataframe. For it I am using pandas such that my code looks like this:

def get_all_sql_data(connection):

    code = 'select * from table1'
    data = pd.read_sql(code, connection)
    ...
    ...
    ...
    return value

However, since I would not like to take my data from our databases in the test code, I am looking to substitute this data with data from a csv file in my test.

I know how to do this using mocks if 'data' is an explicit argument of the function. Is there a way for me to replace this variable within the function with the data I would like to use? If not, is there a better workaround for this testing problem?

Aucun commentaire:

Enregistrer un commentaire