Skip to content

Commit

Permalink
shut down server and exit pytest when test fails (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Wigley authored Oct 12, 2021
1 parent 55c76f4 commit 06a7647
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 43 deletions.
3 changes: 0 additions & 3 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def test_rpc_build_threads(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
# first run dbt to get the model built
Expand Down Expand Up @@ -102,7 +101,6 @@ def test_rpc_build_state(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
state_dir = os.path.join(project_root, 'state')
Expand Down Expand Up @@ -176,7 +174,6 @@ def test_rpc_build_selectors(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
# test simple resource_types param
Expand Down
2 changes: 0 additions & 2 deletions tests/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_rpc_compile_threads(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
results = querier.async_wait_for_result(querier.compile(threads=5))
Expand All @@ -42,7 +41,6 @@ def test_rpc_compile_state(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
state_dir = os.path.join(project_root, 'state')
Expand Down
1 change: 0 additions & 1 deletion tests/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def test_rpc_compile_sql_concurrency(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down
2 changes: 0 additions & 2 deletions tests/test_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def test_rpc_deps_packages(project_root, profiles_root, dbt_profile, unique_sche
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
criteria='error',
)
with querier_ctx as querier:
Expand Down Expand Up @@ -162,7 +161,6 @@ def test_rpc_deps_after_list(project_root, profiles_root, dbt_profile, unique_sc
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
criteria='error',
)
with querier_ctx as querier:
Expand Down
7 changes: 0 additions & 7 deletions tests/test_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_rpc_basics(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down Expand Up @@ -77,7 +76,6 @@ def test_rpc_status_error(project_root, profiles_root, dbt_profile, unique_schem
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
criteria='error',
)
with querier_ctx as querier:
Expand Down Expand Up @@ -143,7 +141,6 @@ def test_gc_change_interval(project_root, profiles_root, dbt_profile, unique_sch
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down Expand Up @@ -190,7 +187,6 @@ def test_ps_poll_output_match(project_root, profiles_root, dbt_profile, unique_s
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down Expand Up @@ -265,7 +261,6 @@ def test_get_status(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down Expand Up @@ -314,7 +309,6 @@ def test_missing_tag_sighup(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
# everything is fine
Expand Down Expand Up @@ -354,7 +348,6 @@ def test_get_manifest(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down
4 changes: 0 additions & 4 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_rpc_run_threads(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
results = querier.async_wait_for_result(querier.run(threads=5))
Expand All @@ -46,7 +45,6 @@ def test_rpc_run_vars(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand All @@ -70,7 +68,6 @@ def test_rpc_run_vars_compiled(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
results = querier.async_wait_for_result(querier.cli_args('--no-partial-parse run --vars "{materialized_var: table}"'))
Expand All @@ -93,7 +90,6 @@ def test_rpc_run_state_defer(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
state_dir = os.path.join(project_root, 'state')
Expand Down
2 changes: 0 additions & 2 deletions tests/test_run_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def test_run_operation(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down Expand Up @@ -80,7 +79,6 @@ def test_run_operation_cli(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down
1 change: 0 additions & 1 deletion tests/test_run_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_rpc_run_sql_nohang(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
querier.async_wait_for_result(querier.run_sql('select 1 as id'))
3 changes: 0 additions & 3 deletions tests/test_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def test_rpc_seed_threads(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down Expand Up @@ -50,7 +49,6 @@ def test_rpc_seed_include_exclude(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down Expand Up @@ -79,7 +77,6 @@ def test_rpc_seed_state(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
state_dir = os.path.join(project_root, 'state')
Expand Down
6 changes: 1 addition & 5 deletions tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def test_snapshots(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down Expand Up @@ -83,7 +82,6 @@ def test_snapshots_cli(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down Expand Up @@ -115,7 +113,6 @@ def test_rpc_snapshot_threads(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand All @@ -140,7 +137,6 @@ def test_rpc_snapshot_state(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
state_dir = os.path.join(project_root, 'state')
Expand Down Expand Up @@ -169,4 +165,4 @@ def test_rpc_snapshot_state(
results = querier.async_wait_for_result(
querier.snapshot(state='./state', select=['state:modified']),
)
assert len(results['results']) == 0
assert len(results['results']) == 0
2 changes: 0 additions & 2 deletions tests/test_source_freshness.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def test_source_snapshot_freshness(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down Expand Up @@ -105,7 +104,6 @@ def test_source_freshness(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)

with querier_ctx as querier:
Expand Down
2 changes: 0 additions & 2 deletions tests/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_rpc_test_threads(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
# first run dbt to get the model built
Expand Down Expand Up @@ -77,7 +76,6 @@ def test_rpc_test_state(
project_dir=project_root,
profiles_dir=profiles_root,
schema=unique_schema,
test_kwargs={},
)
with querier_ctx as querier:
state_dir = os.path.join(project_root, 'state')
Expand Down
18 changes: 9 additions & 9 deletions tests/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import base64
import json
import os
import pytest
import random
import signal
import socket
Expand Down Expand Up @@ -542,10 +541,12 @@ def rpc_server(
cli_vars = '{{test_run_schema: {}}}'.format(schema)

proc = _first_server(project_dir, cli_vars, profiles_dir, criteria, target)
yield proc
if proc.is_alive():
os.kill(proc.pid, signal.SIGKILL)
proc.join()
try:
yield proc
finally:
if proc.is_alive():
os.kill(proc.pid, signal.SIGKILL)
proc.join()


class ProjectDefinition:
Expand Down Expand Up @@ -665,9 +666,9 @@ def execute(adapter, sql):


@contextmanager
def built_schema(project_dir, schema, profiles_dir, test_kwargs, project_def):
def built_schema(project_dir, schema, profiles_dir, project_def):
# make our args, write our project out
args = TestArgs(profiles_dir=profiles_dir, kwargs=test_kwargs)
args = TestArgs(profiles_dir=profiles_dir)
project_def.write_to(project_dir)
# build a config of our own
os.chdir(project_dir)
Expand All @@ -692,7 +693,6 @@ def get_querier(
project_dir,
profiles_dir,
schema,
test_kwargs,
criteria='ready',
target=None,
):
Expand All @@ -702,7 +702,7 @@ def get_querier(
)
schema_ctx = built_schema(
project_dir=project_dir, schema=schema, profiles_dir=profiles_dir,
test_kwargs={}, project_def=project_def,
project_def=project_def,
)
with schema_ctx, server_ctx as server:
yield Querier(server)
Expand Down

0 comments on commit 06a7647

Please sign in to comment.