You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix make test for running integration tests locally (#591)
* Remove venv from CircleCI
* Utilize latest minor version of Python 3.9 for CircleCI (rather than pinned patch version)
* Align local environment variables with CircleCI
* Ignore changes related to running integration tests
* Move the make file to the project root
* Refactor make commands to run integration tests
* Update instructions for running tests
* Implementation guidelines
* Switch order of testing all models vs. a single model in the instructions
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+11-14
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,12 @@
3
3
`dbt-utils` is open source software. It is what it is today because community members have opened issues, provided feedback, and [contributed to the knowledge loop](https://www.getdbt.com/dbt-labs/values/). Whether you are a seasoned open source contributor or a first-time committer, we welcome and encourage you to contribute code, documentation, ideas, or problem statements to this project.
4
4
5
5
1.[About this document](#about-this-document)
6
-
2.[Getting the code](#getting-the-code)
7
-
3.[Setting up an environment](#setting-up-an-environment)
1.[Submitting a Pull Request](#submitting-a-pull-request)
11
12
12
13
## About this document
13
14
@@ -52,16 +53,12 @@ These are the tools used in `dbt-utils` development and testing:
52
53
53
54
A deep understanding of these tools in not required to effectively contribute to `dbt-utils`, but we recommend checking out the attached documentation if you're interested in learning more about each one.
54
55
55
-
#### Virtual environments
56
+
##Implementation guidelines
56
57
57
-
We strongly recommend using virtual environments when developing code in `dbt-utils`. We recommend creating this virtualenv
58
-
in the root of the `dbt-utils` repository. To create a new virtualenv, run:
59
-
```sh
60
-
python3 -m venv env
61
-
source env/bin/activate
62
-
```
63
-
64
-
This will create and activate a new Python virtual environment.
58
+
Ensure that changes will work on "non-core" adapters by:
59
+
- dispatching any new macro(s) so non-core adapters can also use them (e.g. [the `star()` source](https://github.com/fishtown-analytics/dbt-utils/blob/master/macros/sql/star.sql))
60
+
- using the `limit_zero()` macro in place of the literal string: `limit 0`
61
+
- using `dbt_utils.type_*` macros instead of explicit datatypes (e.g. `dbt_utils.type_timestamp()` instead of `TIMESTAMP`
Edit the env file for your TARGET in `integration_tests/.env/[TARGET].env`.
17
+
18
+
Load the environment variables:
19
+
```shell
20
+
set -a;source integration_tests/.env/[TARGET].env;set +a
21
+
```
2
22
3
-
To run the integration tests on your local machine, like they will get run in the CI (using CircleCI), you can do the following:
23
+
or more specific:
24
+
```shell
25
+
set -a;source integration_tests/.env/postgres.env;set +a
26
+
```
4
27
5
-
Assuming you are in the `integration_tests` folder,
28
+
#### Setup Postgres (optional)
6
29
7
-
```bash
8
-
make test target=[postgres|redshift|...] [models=...] [seeds=...]
30
+
Docker and `docker-compose` are both used in testing. Specific instructions for your OS can be found [here](https://docs.docker.com/get-docker/).
31
+
32
+
Postgres offers the easiest way to test most `dbt-utils` functionality today. Its tests are the fastest to run, and the easiest to set up. To run the Postgres integration tests, you'll have to do one extra step of setting up the test database:
33
+
34
+
```shell
35
+
make setup-db
36
+
```
37
+
or, alternatively:
38
+
```shell
39
+
docker-compose up --detach postgres
40
+
```
41
+
42
+
### Setup virtual environment
43
+
44
+
We strongly recommend using virtual environments when developing code in `dbt-utils`. We recommend creating this virtualenv
45
+
in the root of the `dbt-utils` repository. To create a new virtualenv, run:
46
+
```shell
47
+
python3 -m venv env
48
+
source env/bin/activate
49
+
```
50
+
51
+
This will create and activate a new Python virtual environment.
52
+
53
+
### Installation for development
54
+
55
+
First make sure that you set up your virtual environment as described above. Also ensure you have the latest version of pip installed with `pip install --upgrade pip`. Next, install `dbt-core` (and its dependencies) with:
- Copy contents from `integration_tests/ci/sample.profiles.yml` into `~/.dbt/profiles.yml`.
105
+
106
+
#### Add your integration test
29
107
This directory contains an example dbt project which tests the macros in the `dbt-utils` package. An integration test typically involves making 1) a new seed file 2) a new model file 3) a generic test to assert anticipated behaviour.
30
108
31
109
For an example integration tests, check out the tests for the `get_url_parameter` macro:
@@ -35,13 +113,20 @@ For an example integration tests, check out the tests for the `get_url_parameter
35
113
3. [Model to test the macro](https://github.com/fishtown-analytics/dbt-utils/blob/master/integration_tests/models/web/test_urls.sql)
36
114
4. [A generic test to assert the macro works as expected](https://github.com/fishtown-analytics/dbt-utils/blob/master/integration_tests/models/web/schema.yml#L2)
37
115
38
-
39
116
Once you've added all of these files, you should be able to run:
117
+
118
+
Assuming you are in the `integration_tests` folder,
119
+
```shell
120
+
dbt deps --target {your_target}
121
+
dbt seed --target {your_target}
122
+
dbt run --target {your_target} --model {your_model_name}
123
+
dbt test --target {your_target} --model {your_model_name}
0 commit comments