Here are the steps to run the integration tests:
- Set environment variables
- Run Docker containers (optional)
- Run tests
Assuming the applicable dbt-tests-adapter package is installed and environment variables are set:
PYTHONPATH=. pytest tests/functional/adapter/test_basic.pypip install -r ./dev-requirements.txt
Python 3.8 and 3.9 are supported test targets and may need to be installed before tests can run.
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.8 python3.8-distutils python3.9 python3.9-distutils
Create the following environment variables (e.g., export {VARIABLE}={value} in a bash shell or via a tool like direnv):
DBT_MYSQL_SERVER_NAMEDBT_MYSQL_USERNAMEDBT_MYSQL_PASSWORDDBT_MARIADB_105_PORTDBT_MYSQL_57_PORTDBT_MYSQL_80_PORT
.env.example has a listing of environment variables and values. You can use it with Docker by configuring a .env file with appropriate variables:
cp .env.example .env
$EDITOR .envBy default, Docker will automatically load environment variables from a file named .env.
This command will launch local databases for testing:
docker-compose up -dSkip to down below and follow the instructions to "Run tests".
When finished using the containers:
docker-compose downMore complicated docker setup commands
Here is one guide on "How to Run MySQL in a Docker Container on macOS with Persistent Local Data".
In the docker commands below, the default MySQL username is root and the default server name is localhost. If they are used unaltered, then you should set the following environment variable values:
DBT_MYSQL_SERVER_NAME=localhost
DBT_MYSQL_USERNAME=root
If you use any bash special characters in your password (like $), then you will need to escape them (like DBT_MYSQL_PASSWORD=pas\$word instead of DBT_MYSQL_PASSWORD=pas$word).
docker run --name mysql8.0 --net dev-network -v /Users/YOUR_USERNAME/Develop/mysql_data/8.0:/var/lib/mysql -p 3306:3306 -d -e MYSQL_ROOT_PASSWORD=$DBT_MYSQL_PASSWORD mysql:8.0
Contents of /Users/YOUR_USERNAME/Develop/mysql_data/5.7/my.cnf:
[mysqld]
explicit_defaults_for_timestamp = true
sql_mode = "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ALLOW_INVALID_DATES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
docker run --name mysql5.7 --net dev-network -v /Users/YOUR_USERNAME/Develop/mysql_data/5.7:/var/lib/mysql -v /Users/YOUR_USERNAME/Develop/mysql_data/5.7/my.cnf:/etc/my.cnf -p 3307:3306 -d -e MYSQL_ROOT_PASSWORD=$DBT_MYSQL_PASSWORD mysql:5.7
Run all the tests via make:
make unit
make integrationOr run all the tests via tox:
toxOr run the test specs directly
PYTHONPATH=. pytest -v --profile mysql tests/functional && \
PYTHONPATH=. pytest -v --profile mysql5 tests/functional && \
PYTHONPATH=. pytest -v --profile mariadb tests/functionalOr run a single test
pytest -v --profile mysql tests/functional/adapter/test_basic.py::TestEmptyMySQL::test_empty