1

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?

Michael Tamillow
  • 415
  • 4
  • 11
  • So, ultimately you are looking for `pd.read_sql(code, connection)` to return the result of reading a csv file and give you data, correct? – idjaw Apr 06 '16 at 13:54
  • More or less, that is correct. I had imagined that pd.read_sql(code, connection) would be bypassed entirely in the test in favor of the variable 'data' already being in the correct form and content I would like to test. – Michael Tamillow Apr 06 '16 at 17:06

0 Answers0