Reputation: 3355
I have a function to read data from a MySQL database:
def example(mysql_engine) -> DataFrame:
query = """SELECT col_1 FROM xxx.xxx"""
df = pandas.read_sql(query, mysql_engine)
return df
mysql_engine
is returned by another function, now I want to write unit tests to validate the column name col_1
and datatype in df
, is there an example I can follow? Do I need to set up a real database engine in unit test?
Upvotes: 1
Views: 1416
Reputation: 302
You can use assert col_1 in df.columns
for the unit tests.
For the Database engine, you can use a mock object. You can check this link from the standard library.
Upvotes: 0