Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New testing framework #109

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dbt-integration-tests
test/integration/.user.yml
.DS_Store
.vscode
logs
1 change: 1 addition & 0 deletions dbt/adapters/mariadb/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def open(cls, connection):
kwargs["host"] = credentials.server
kwargs["user"] = credentials.username
kwargs["passwd"] = credentials.password
kwargs["buffered"] = True

if credentials.ssl_disabled:
kwargs["ssl_disabled"] = credentials.ssl_disabled
Expand Down
1 change: 1 addition & 0 deletions dbt/adapters/mysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def open(cls, connection):
kwargs["host"] = credentials.server
kwargs["user"] = credentials.username
kwargs["passwd"] = credentials.password
kwargs["buffered"] = True

if credentials.port:
kwargs["port"] = credentials.port
Expand Down
1 change: 1 addition & 0 deletions dbt/adapters/mysql5/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def open(cls, connection):
kwargs["host"] = credentials.server
kwargs["user"] = credentials.username
kwargs["passwd"] = credentials.password
kwargs["buffered"] = True

if credentials.ssl_disabled:
kwargs["ssl_disabled"] = credentials.ssl_disabled
Expand Down
8 changes: 8 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[pytest]
filterwarnings =
ignore:.*'soft_unicode' has been renamed to 'soft_str'*:DeprecationWarning
ignore:unclosed file .*:ResourceWarning
env_files =
test.env
testpaths =
tests/functional
6 changes: 4 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
wheel
twine
freezegun==0.3.9
pytest==6.0.2
pytest~=7.0
mock>=1.3.0
flake8>=3.5.0
pytz==2017.2
Expand All @@ -12,4 +12,6 @@ pytest-xdist>=2.1.0,<3
flaky>=3.5.3,<4

# Test requirements
pytest-dbt-adapter==0.6.0
markupsafe==2.0.1
dbt-tests-adapter==1.1.0
pytest-dotenv
24 changes: 0 additions & 24 deletions test/integration/mariadb-10.5.dbtspec

This file was deleted.

26 changes: 0 additions & 26 deletions test/integration/mysql-5.7.dbtspec

This file was deleted.

24 changes: 0 additions & 24 deletions test/integration/mysql-8.0.dbtspec

This file was deleted.

23 changes: 0 additions & 23 deletions test/mysql.dbtspec

This file was deleted.

6 changes: 5 additions & 1 deletion test/README.md → tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Here are the steps to run the integration tests:

Assuming the applicable `pytest-dbt-adapter` package is installed and environment variables are set:
```bash
pytest test/mysql.dbtspec
PYTHONPATH=. pytest tests/functional/adapter/basic/mysql_test.py
```

## Full example
Expand Down Expand Up @@ -89,6 +89,10 @@ sql_mode = "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ALLOW_INVALID

Run the test specs in this repository:
```shell
PYTHONPATH=. pytest -v tests/functional/adapter/basic/mysql_80.py && \
PYTHONPATH=. pytest -v tests/functional/adapter/basic/mysql_57.py && \
PYTHONPATH=. pytest -v tests/functional/adapter/basic/maria_105.py
```
pytest -v test/integration/mariadb-10.5.dbtspec && \
pytest -v test/integration/mysql-5.7.dbtspec && \
pytest -v test/integration/mysql-8.0.dbtspec
Expand Down
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest
import os

# Import the fuctional fixtures as a plugin
# Note: fixtures with session scope need to be local

pytest_plugins = ["dbt.tests.fixtures.project"]

# The profile dictionary, used to write out profiles.yml
# dbt will supply a unique schema per test, so we do not specify 'schema' here
@pytest.fixture(scope="class")
def dbt_profile_target():
return {
"type": "mysql",
"threads": 1,
"host": os.getenv("DBT_MYSQL_SERVER_NAME", "127.0.0.1"),
"user": os.getenv("DBT_MYSQL_USERNAME", "root"),
"password": os.getenv("DBT_MYSQL_PASSWORD", ""),
"port": os.getenv("DBT_MYSQL_PORT", 3306),
}
71 changes: 71 additions & 0 deletions tests/functional/adapter/basic/mariadb-105.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import os

import pytest

from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations
from dbt.tests.adapter.basic.test_singular_tests import BaseSingularTests
from dbt.tests.adapter.basic.test_singular_tests_ephemeral import (
BaseSingularTestsEphemeral,
)
from dbt.tests.adapter.basic.test_empty import BaseEmpty
from dbt.tests.adapter.basic.test_ephemeral import BaseEphemeral
from dbt.tests.adapter.basic.test_incremental import BaseIncremental
from dbt.tests.adapter.basic.test_generic_tests import BaseGenericTests
from dbt.tests.adapter.basic.test_snapshot_check_cols import BaseSnapshotCheckCols
from dbt.tests.adapter.basic.test_snapshot_timestamp import BaseSnapshotTimestamp
from dbt.tests.adapter.basic.test_adapter_methods import BaseAdapterMethod
from dbt.tests.util import run_dbt, check_relations_equal


@pytest.fixture(scope="class")
def dbt_profile_target():
return {
"type": "mariadb",
"threads": 1,
"host": os.getenv("DBT_MYSQL_SERVER_NAME", "127.0.0.1"),
"user": os.getenv("DBT_MYSQL_USERNAME", "root"),
"password": os.getenv("DBT_MYSQL_PASSWORD", ""),
"port": os.getenv("DBT_MARIADB_105_PORT", 3306),
}

class TestEmptyMyAdapter(BaseEmpty):
pass


class TestSimpleMaterializationsMyAdapter(BaseSimpleMaterializations):
pass


class TestEphemeralMyAdapter(BaseEphemeral):
pass


class TestIncrementalMyAdapter(BaseIncremental):
pass


class TestSnapshotCheckColsMyAdapter(BaseSnapshotCheckCols):
pass


class TestSnapshotTimestampMyAdapter(BaseSnapshotTimestamp):
pass


class TestSingularTestsEphemeral(BaseSingularTestsEphemeral):
pass


class TestSingularTestsMyAdapter(BaseSingularTests):
pass


class TestGenericTestsMyAdapter(BaseGenericTests):
pass


class TestBaseAdapterMethod(BaseAdapterMethod):
def test_adapter_methods(self, project, equal_tables):
result = run_dbt()
assert len(result) == 3
check_relations_equal(project.adapter, equal_tables)
71 changes: 71 additions & 0 deletions tests/functional/adapter/basic/mysql-57.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import os

import pytest

from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations
from dbt.tests.adapter.basic.test_singular_tests import BaseSingularTests
from dbt.tests.adapter.basic.test_singular_tests_ephemeral import (
BaseSingularTestsEphemeral,
)
from dbt.tests.adapter.basic.test_empty import BaseEmpty
from dbt.tests.adapter.basic.test_ephemeral import BaseEphemeral
from dbt.tests.adapter.basic.test_incremental import BaseIncremental
from dbt.tests.adapter.basic.test_generic_tests import BaseGenericTests
from dbt.tests.adapter.basic.test_snapshot_check_cols import BaseSnapshotCheckCols
from dbt.tests.adapter.basic.test_snapshot_timestamp import BaseSnapshotTimestamp
from dbt.tests.adapter.basic.test_adapter_methods import BaseAdapterMethod
from dbt.tests.util import run_dbt, check_relations_equal


@pytest.fixture(scope="class")
def dbt_profile_target():
return {
"type": "mysql",
"threads": 1,
"host": os.getenv("DBT_MYSQL_SERVER_NAME", "127.0.0.1"),
"user": os.getenv("DBT_MYSQL_USERNAME", "root"),
"password": os.getenv("DBT_MYSQL_PASSWORD", ""),
"port": os.getenv("DBT_MYSQL_57_PORT", 3306),
}

class TestEmptyMyAdapter(BaseEmpty):
pass


class TestSimpleMaterializationsMyAdapter(BaseSimpleMaterializations):
pass

@pytest.mark.skip(reason="Ephemeral materializations not supported for MySQL 5.7")
class TestEphemeralMyAdapter(BaseEphemeral):
pass


class TestIncrementalMyAdapter(BaseIncremental):
pass


class TestSnapshotCheckColsMyAdapter(BaseSnapshotCheckCols):
pass


class TestSnapshotTimestampMyAdapter(BaseSnapshotTimestamp):
pass

@pytest.mark.skip(reason="Ephemeral materializations not supported for MySQL 5.7")
class TestSingularTestsEphemeral(BaseSingularTestsEphemeral):
pass


class TestSingularTestsMyAdapter(BaseSingularTests):
pass


class TestGenericTestsMyAdapter(BaseGenericTests):
pass


class TestBaseAdapterMethod(BaseAdapterMethod):
def test_adapter_methods(self, project, equal_tables):
result = run_dbt()
assert len(result) == 3
check_relations_equal(project.adapter, equal_tables)
Loading