Skip to content

Latest commit

 

History

History
126 lines (89 loc) · 3.56 KB

README.md

File metadata and controls

126 lines (89 loc) · 3.56 KB

Testing dbt-mysql

Overview

Here are the steps to run the integration tests:

  1. Set environment variables
  2. Run Docker containers (optional)
  3. Run tests

Simple example

Assuming the applicable dbt-tests-adapter package is installed and environment variables are set:

PYTHONPATH=. pytest tests/functional/adapter/test_basic.py

Full example

Prerequisites

Dependencies

pip install -r ./dev-requirements.txt

Python Version

Python 3.8 and 3.9 are supported test targets and may need to be installed before tests can run.

Ubuntu
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

Environment variables

Create the following environment variables (e.g., export {VARIABLE}={value} in a bash shell or via a tool like direnv):

  • DBT_MYSQL_SERVER_NAME
  • DBT_MYSQL_USERNAME
  • DBT_MYSQL_PASSWORD
  • DBT_MARIADB_105_PORT
  • DBT_MYSQL_57_PORT
  • DBT_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 .env

By default, Docker will automatically load environment variables from a file named .env.

Docker

Easiest

This command will launch local databases for testing:

docker-compose up -d

Skip to down below and follow the instructions to "Run tests".

When finished using the containers:

docker-compose down

Harder

More 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).

MySQL 8.0

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

MySQL 5.7

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 tests

Run all the tests via make:

make unit
make integration

Or run all the tests via tox:

tox

Or 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/functional

Or run a single test

pytest -v --profile mysql tests/functional/adapter/test_basic.py::TestEmptyMySQL::test_empty