diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c43ac0..741f863 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- Add target flag ([issue](/~https://github.com/godatadriven/pytest-dbt-core/issues/11), [PR](/~https://github.com/godatadriven/pytest-dbt-core/pull/13)) - Delete session module [is included in dbt-spark](/~https://github.com/dbt-labs/dbt-spark/issues/272) - Add Github templates diff --git a/setup.cfg b/setup.cfg index d87fa08..5017be2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,8 +21,7 @@ classifiers = packages = find: package_dir = =src install_requires = - dbt-spark>=1.0.0,<2.0.0 - pyspark>=3.0.0,<4.0.0 + dbt-core>=1.0.0,<2.0.0 python_requires = >=3.6 [options.packages.find] @@ -30,6 +29,8 @@ where = src [options.extras_require] test = + dbt-spark[ODBC]>=1.0.0,<2.0.0 + pyspark>=3.0.0,<4.0.0 pre-commit>=2.14.1 pytest>=6.2.5 pytest-spark>=0.6.0 @@ -57,10 +58,11 @@ warn_redundant_casts = True addopts = --cov=src --cov-report=xml:pytest-coverage.xml --junitxml=pytest-output.xml - --doctest-glob="README.md" + --doctest-glob=README.md --doctest-modules --ignore=scripts/ - --dbt-project-dir="./tests/dbt_project" + --dbt-project-dir=./tests/dbt_project + --dbt-target=test spark_options = spark.app.name: dbt-core spark.executor.instances: 1 diff --git a/src/pytest_dbt_core/fixtures.py b/src/pytest_dbt_core/fixtures.py index 42a6b91..9a05382 100644 --- a/src/pytest_dbt_core/fixtures.py +++ b/src/pytest_dbt_core/fixtures.py @@ -33,9 +33,14 @@ class Args: dbt is written as command line tool, therefore the entrypoints of dbt expect (parsed) arguments. To reuse dbt's entrypoints we mock the (minimally) arguments here. + + Source + ------ + See argparse `add_argument` statements in `dbt.main`. """ project_dir: str + target: str | None @pytest.fixture @@ -53,8 +58,11 @@ def config(request: SubRequest) -> RuntimeConfig: RuntimeConfig The runtime config. """ - project_dir = request.config.getoption("--dbt-project-dir") - config = RuntimeConfig.from_args(Args(project_dir=project_dir)) + args = Args( + project_dir=request.config.getoption("--dbt-project-dir"), + target=request.config.getoption("--dbt-target"), + ) + config = RuntimeConfig.from_args(args) return config diff --git a/src/pytest_dbt_core/plugin.py b/src/pytest_dbt_core/plugin.py index 2732e96..c657b79 100644 --- a/src/pytest_dbt_core/plugin.py +++ b/src/pytest_dbt_core/plugin.py @@ -16,7 +16,7 @@ def pytest_addoption(parser: Parser) -> None: """ - Add pytest option. + Add pytest options. Parameters ---------- @@ -29,3 +29,8 @@ def pytest_addoption(parser: Parser) -> None: type="string", default=os.getcwd(), ) + parser.addoption( + "--dbt-target", + help="Which target to load for the given profile", + type="string", + ) diff --git a/tests/dbt_project/profiles.yml b/tests/dbt_project/profiles.yml index 0574136..620d1e7 100644 --- a/tests/dbt_project/profiles.yml +++ b/tests/dbt_project/profiles.yml @@ -1,6 +1,16 @@ dbt_project: - target: test + target: dev outputs: + dev: + type: spark + method: odbc + schema: cor + host: https://adb-123456789.00.azuredatabricks.net + port: 443 + organization: "123456789" + cluster: 1234-567890-12ab3c4d + token: dapi1abc2345de6f78g901h234ij5klm6789-1 + driver: /Library/simba/spark/lib/libsparkodbc_sbu.dylib test: type: spark method: session diff --git a/tests/dbt_project/tests/test_fetch_single_statement.py b/tests/dbt_project/tests/test_fetch_single_statement.py index ddd3380..7ee7042 100644 --- a/tests/dbt_project/tests/test_fetch_single_statement.py +++ b/tests/dbt_project/tests/test_fetch_single_statement.py @@ -1,6 +1,5 @@ import pytest from dbt.clients.jinja import MacroGenerator -from pyspark.sql import SparkSession @pytest.mark.parametrize( @@ -8,8 +7,6 @@ ["macro.dbt_project.fetch_single_statement"], indirect=True, ) -def test_create_table( - spark_session: SparkSession, macro_generator: MacroGenerator -) -> None: +def test_create_table(macro_generator: MacroGenerator) -> None: out = macro_generator("SELECT 1") assert out == 1