-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cea0294
commit 80a9141
Showing
1 changed file
with
19 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,31 @@ | ||
import pytest | ||
import sys | ||
import importlib | ||
import dbt | ||
import copy | ||
|
||
|
||
@pytest.fixture | ||
def remove_agate_from_path(): | ||
"""conftest and other envs load agate modules upon initilization so we need | ||
to remove their presence from module tracking to assess correctness of direct imports""" | ||
def test_lazy_loading_agate(): | ||
"""If agate is imported directly here or in any of the subsequent files, this test will fail. Also test that our assumptions about imports affecting sys modules hold. | ||
original_sys_path = sys.modules.copy() | ||
Because other tests use Agate, we must be extra careful with state changes. | ||
""" | ||
|
||
# import ahead of time to avoid reimporting agate upon package initialization | ||
import dbt.adapters.snowflake.__init__ | ||
|
||
modules_to_remove = [m for m in sys.modules if "agate" in m] | ||
for m in modules_to_remove: | ||
del sys.modules[m] | ||
original_modules = copy.copy(sys.modules) | ||
try: | ||
agate_modules = [m for m in sys.modules if "agate" in m] | ||
for m in agate_modules: | ||
del sys.modules[m] | ||
|
||
yield | ||
sys.path = original_sys_path | ||
import dbt.adapters.snowflake.__init__ | ||
|
||
importlib.reload(dbt.adapters.snowflake.connections) | ||
importlib.reload(dbt.adapters.snowflake.impl) | ||
importlib.reload(dbt.adapters.snowflake.relation_configs.base) | ||
importlib.reload(dbt.adapters.snowflake.relation_configs.dynamic_table) | ||
assert not any([module_name for module_name in sys.modules if "agate" in module_name]) | ||
|
||
def test_lazy_loading_agate(remove_agate_from_path): | ||
"""If agate is imported directly here or in any of the subsequent files, this test will fail. Also test that our assumptions about imports affecting sys modules hold.""" | ||
|
||
import dbt | ||
|
||
importlib.reload(dbt.adapters.snowflake.connections) | ||
importlib.reload(dbt.adapters.snowflake.impl) | ||
importlib.reload(dbt.adapters.snowflake.relation_configs.base) | ||
importlib.reload(dbt.adapters.snowflake.relation_configs.dynamic_table) | ||
assert not any([module_name for module_name in sys.modules if "agate" in module_name]) | ||
|
||
import agate | ||
|
||
assert any([module_name for module_name in sys.modules if "agate" in module_name]) | ||
finally: | ||
sys.modules = original_modules |