Skip to content

Commit e36333c

Browse files
Weird tests not running
1 parent 142d157 commit e36333c

File tree

3 files changed

+102
-4
lines changed

3 files changed

+102
-4
lines changed

conftest.py

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import pytest
2+
import os
3+
4+
pytest_plugins = ["dbt.tests.fixtures.project"]
5+
6+
7+
def pytest_addoption(parser):
8+
parser.addoption("--profile", action="store", default="postgres", type=str)
9+
10+
11+
# Using @pytest.mark.skip_profile('postgres') uses the 'skip_by_profile_type'
12+
# autouse fixture below
13+
def pytest_configure(config):
14+
config.addinivalue_line(
15+
"markers",
16+
"skip_profile(profile): skip test for the given profile",
17+
)
18+
config.addinivalue_line(
19+
"markers",
20+
"only_profile(profile): only test the given profile",
21+
)
22+
23+
24+
@pytest.fixture(scope="session")
25+
def dbt_profile_target(request):
26+
profile_type = request.config.getoption("--profile")
27+
if profile_type == "postgres":
28+
target = postgres_target()
29+
elif profile_type == "redshift":
30+
target = redshift_target()
31+
elif profile_type == "snowflake":
32+
target = snowflake_target()
33+
elif profile_type == "bigquery":
34+
target = bigquery_target()
35+
else:
36+
raise ValueError(f"Invalid profile type '{profile_type}'")
37+
return target
38+
39+
40+
def postgres_target():
41+
return {
42+
"type": "postgres",
43+
"host": os.getenv('POSTGRES_TEST_HOST'),
44+
"user": os.getenv('POSTGRES_TEST_USER'),
45+
"pass": os.getenv('POSTGRES_TEST_PASS'),
46+
"port": int(os.getenv('POSTGRES_TEST_PORT')),
47+
"dbname": os.getenv('POSTGRES_TEST_DBNAME'),
48+
}
49+
50+
51+
def redshift_target():
52+
return {
53+
"type": "redshift",
54+
"host": os.getenv('REDSHIFT_TEST_HOST'),
55+
"user": os.getenv('REDSHIFT_TEST_USER'),
56+
"pass": os.getenv('REDSHIFT_TEST_PASS'),
57+
"port": int(os.getenv('REDSHIFT_TEST_PORT')),
58+
"dbname": os.getenv('REDSHIFT_TEST_DBNAME'),
59+
}
60+
61+
62+
def bigquery_target():
63+
return {
64+
"type": "bigquery",
65+
"method": "service-account",
66+
"keyfile": os.getenv('BIGQUERY_SERVICE_KEY_PATH'),
67+
"project": os.getenv('BIGQUERY_TEST_DATABASE'),
68+
}
69+
70+
71+
def snowflake_target():
72+
return {
73+
"type": "snowflake",
74+
"account": os.getenv('SNOWFLAKE_TEST_ACCOUNT'),
75+
"user": os.getenv('SNOWFLAKE_TEST_USER'),
76+
"password": os.getenv('SNOWFLAKE_TEST_PASSWORD'),
77+
"role": os.getenv('SNOWFLAKE_TEST_ROLE'),
78+
"database": os.getenv('SNOWFLAKE_TEST_DATABASE'),
79+
"warehouse": os.getenv('SNOWFLAKE_TEST_WAREHOUSE'),
80+
}
81+
82+
83+
@pytest.fixture(autouse=True)
84+
def skip_by_profile_type(request):
85+
profile_type = request.config.getoption("--profile")
86+
if request.node.get_closest_marker("skip_profile"):
87+
for skip_profile_type in request.node.get_closest_marker("skip_profile").args:
88+
if skip_profile_type == profile_type:
89+
pytest.skip("skipped on '{profile_type}' profile")
90+
91+
92+
@pytest.fixture(autouse=True)
93+
def only_profile_type(request):
94+
profile_type = request.config.getoption("--profile")
95+
if request.node.get_closest_marker("only_profile"):
96+
for only_profile_type in request.node.get_closest_marker("only_profile").args:
97+
if only_profile_type != profile_type:
98+
pytest.skip("skipped on '{profile_type}' profile")

dbt_project.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ snapshot-paths: ["jaffle_shop/snapshots"]
1313
target-path: "target"
1414
clean-targets:
1515
- "target"
16-
- "dbt_modules"
16+
- "dbt_packages"
1717
- "logs"
1818

1919
require-dbt-version: [">=1.0.0", "<2.0.0"]

packages.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
packages:
22
- package: dbt-labs/dbt_utils
3-
version: 0.8.6
3+
version: 1.1.1
44
- package: dbt-labs/spark_utils
55
version: 0.3.0
66
- package: dbt-labs/codegen
7-
version: 0.7.0
7+
version: 0.12.1
88
- package: dbt-labs/dbt_project_evaluator
9-
version: 0.1.3
9+
version: 0.6.2

0 commit comments

Comments
 (0)