diff --git a/README.md b/README.md index 5212e5f..9b4da3e 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,41 @@ We welcome contributions to this repo! To contribute a new feature or a fix, please open a Pull Request with 1) your changes and 2) updated documentation for the `README.md` file. +## Testing + +The macros are tested with [`pytest`](https://docs.pytest.org) and +[`pytest-dbt-core`](https://pypi.org/project/pytest-dbt-core/). For example, +the [`create_tables` macro is tested](./tests/test_macros.py) by: + +1. Create a test table (test setup): + ``` python + spark_session.sql(f"CREATE TABLE {table_name} (id int) USING parquet") + ``` +2. Call the macro generator: + ``` python + tables = macro_generator() + ``` +3. Assert test condition: + ``` python + assert simple_table in tables + ``` +4. Delete the test table (test cleanup): + ``` python + spark_session.sql(f"DROP TABLE IF EXISTS {table_name}") + ``` + +A macro is fetched using the +[`macro_generator`](https://pytest-dbt-core.readthedocs.io/en/latest/dbt_spark.html#usage) +fixture and providing the macro name trough +[indirect parameterization](https://docs.pytest.org/en/7.1.x/example/parametrize.html?highlight=indirect#indirect-parametrization): + +``` python +@pytest.mark.parametrize( + "macro_generator", ["macro.spark_utils.get_tables"], indirect=True +) +def test_create_table(macro_generator: MacroGenerator) -> None: +``` + ---- ### Getting started with dbt + Spark