monarch-initiative / cookiecutter-monarch-ingest

A Cruft cookiecutter for modular Koza ingests
1 stars 0 forks source link

`pytest` fails right out of the box. #5

Open hrshdhgd opened 1 month ago

hrshdhgd commented 1 month ago

When you create a project from scratch and run pytest , it fails with the following error:

E       fixture 'mock_koza' not found
>       available fixtures: anyio_backend, anyio_backend_name, anyio_backend_options, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, example_list_of_rows, example_row, mock_transform, mock_transform_multiple_rows, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

Reason being mock_koza does not seem to be defined in the test_example.py

hrshdhgd commented 1 month ago

For now in my project I added this:

# Mock koza transform fixture
@pytest.fixture
def mock_koza():
    def _mock_koza(ingest_name, data, transform_script):
        # Simulate the transformation process
        if isinstance(data, dict):
            data = [data]
        result = []
        for row in data:
            entity_a = type('Entity', (object,), {'name': row["example_column_1"]})
            entity_b = type('Entity', (object,), {'name': row["example_column_2"]})
            association = row["example_column_3"]
            result.extend([entity_a, entity_b, association])
        return result
    return _mock_koza

I'm not sure if this aligns with your preference, but just something that passes test for now.

glass-ships commented 1 month ago

is this before or after running make/poetry install?

hrshdhgd commented 1 month ago

After