sqlmesh icon indicating copy to clipboard operation
sqlmesh copied to clipboard

Python models not referencing to unittest data fixtures

Open bjones325 opened this issue 1 year ago • 2 comments

Python Models use context.resolve_table(model_name) to find the physical table name to query.

When unittesting a python model with data fixtures mocking upstream tables, resolve_table does not resolve to the mocked fixture, IF the upstream table is not a SQLMesh model.

For example, with a model such as:


def execute(...):
      not_a_sqlmesh_model = "catalog.schema.upstream_table_not_a_model"
      table_ref = context.resolve_table(not_a_sqlmesh_model)
      fetchdf(f"SELECT * FROM {table_ref}")

and a unittest yml of:

my_test:
  model: my_model
  inputs:
    catalog.schema.upstream_table_not_a_model:
      rows:
           - col_a: value_a

the table_ref field will resolve to "catalog.schema.upstream_table_not_a_model", and NOT the table generated by the unittest yml.

This makes unittesting Python models dependent on upstream tables, which are NOT sqlmesh models, impossible. Either, context.resolve_table should resolve to the table created by the data fixture, or fetchdf should parse and replace the table reference to point to the data fixture.

bjones325 avatar Feb 25 '25 02:02 bjones325

@themisvaltinos can you please have a look at this

izeigerman avatar Mar 11 '25 18:03 izeigerman

sure I will look into this @izeigerman

themisvaltinos avatar Mar 11 '25 18:03 themisvaltinos