2021-03-18 02:05:05 -04:00
|
|
|
import logging
|
2021-02-11 12:53:44 -08:00
|
|
|
import os
|
2023-10-03 23:17:49 -04:00
|
|
|
import pathlib
|
2021-03-11 02:29:24 -05:00
|
|
|
import time
|
2023-10-03 23:17:49 -04:00
|
|
|
from typing import List
|
2021-03-11 02:29:24 -05:00
|
|
|
|
|
|
|
import pytest
|
2021-02-11 12:53:44 -08:00
|
|
|
|
2023-07-14 15:47:16 -07:00
|
|
|
os.environ["DATAHUB_SUPPRESS_LOGGING_MANAGER"] = "1"
|
2024-11-20 13:48:56 -08:00
|
|
|
os.environ["DATAHUB_TEST_MODE"] = "1"
|
2023-07-14 15:47:16 -07:00
|
|
|
|
2022-07-29 09:41:31 +00:00
|
|
|
# Enable debug logging.
|
|
|
|
logging.getLogger().setLevel(logging.DEBUG)
|
|
|
|
os.environ["DATAHUB_DEBUG"] = "1"
|
|
|
|
|
|
|
|
# Disable telemetry
|
|
|
|
os.environ["DATAHUB_TELEMETRY_ENABLED"] = "false"
|
|
|
|
|
|
|
|
# Reduce retries on GMS, because this causes tests to hang while sleeping
|
|
|
|
# between retries.
|
|
|
|
os.environ["DATAHUB_REST_EMITTER_DEFAULT_RETRY_MAX_TIMES"] = "1"
|
|
|
|
|
|
|
|
# We need our imports to go below the os.environ updates, since mere act
|
|
|
|
# of importing some datahub modules will load env variables.
|
2025-02-12 15:32:31 -08:00
|
|
|
from datahub.testing.pytest_hooks import ( # noqa: F401,E402
|
|
|
|
load_golden_flags,
|
|
|
|
pytest_addoption,
|
|
|
|
)
|
2023-03-15 02:29:54 +05:30
|
|
|
from tests.test_helpers.docker_helpers import ( # noqa: F401,E402
|
|
|
|
docker_compose_command,
|
|
|
|
docker_compose_runner,
|
|
|
|
)
|
2024-10-16 13:50:33 -07:00
|
|
|
from tests.test_helpers.state_helpers import ( # noqa: F401,E402
|
|
|
|
mock_datahub_graph,
|
|
|
|
mock_datahub_graph_instance,
|
|
|
|
)
|
2021-03-11 02:29:24 -05:00
|
|
|
|
2021-11-07 18:53:53 -08:00
|
|
|
try:
|
|
|
|
# See https://github.com/spulec/freezegun/issues/98#issuecomment-590553475.
|
|
|
|
import pandas # noqa: F401
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2025-02-13 08:28:48 -08:00
|
|
|
import freezegun # noqa: E402
|
2024-02-23 11:11:02 -08:00
|
|
|
|
|
|
|
# The freezegun library has incomplete type annotations.
|
|
|
|
# See https://github.com/spulec/freezegun/issues/469
|
|
|
|
freezegun.configure(extend_ignore_list=["datahub.utilities.cooperative_timeout"]) # type: ignore[attr-defined]
|
|
|
|
|
2021-03-11 02:29:24 -05:00
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def mock_time(monkeypatch):
|
|
|
|
def fake_time():
|
|
|
|
return 1615443388.0975091
|
|
|
|
|
|
|
|
monkeypatch.setattr(time, "time", fake_time)
|
2021-06-30 16:53:20 -07:00
|
|
|
|
2021-03-11 02:29:24 -05:00
|
|
|
yield
|
2021-06-30 16:53:20 -07:00
|
|
|
|
|
|
|
|
2023-10-03 23:17:49 -04:00
|
|
|
def pytest_collection_modifyitems(
|
|
|
|
config: pytest.Config, items: List[pytest.Item]
|
|
|
|
) -> None:
|
|
|
|
# https://docs.pytest.org/en/latest/reference/reference.html#pytest.hookspec.pytest_collection_modifyitems
|
|
|
|
# Adapted from https://stackoverflow.com/a/57046943/5004662.
|
|
|
|
|
|
|
|
root = pathlib.Path(config.rootpath)
|
|
|
|
integration_path = root / "tests/integration"
|
|
|
|
|
|
|
|
for item in items:
|
2024-03-04 17:09:22 -08:00
|
|
|
test_path = item.path
|
2023-10-03 23:17:49 -04:00
|
|
|
|
|
|
|
if (
|
|
|
|
"docker_compose_runner" in item.fixturenames # type: ignore[attr-defined]
|
|
|
|
or any(
|
|
|
|
marker.name == "integration_batch_2" for marker in item.iter_markers()
|
|
|
|
)
|
|
|
|
):
|
|
|
|
item.add_marker(pytest.mark.slow)
|
|
|
|
|
|
|
|
is_already_integration = any(
|
|
|
|
marker.name == "integration" for marker in item.iter_markers()
|
|
|
|
)
|
|
|
|
|
|
|
|
if integration_path in test_path.parents or is_already_integration:
|
|
|
|
# If it doesn't have a marker yet, put it in integration_batch_0.
|
|
|
|
if not any(
|
|
|
|
marker.name.startswith("integration_batch_")
|
|
|
|
for marker in item.iter_markers()
|
|
|
|
):
|
|
|
|
item.add_marker(pytest.mark.integration_batch_0)
|
|
|
|
|
|
|
|
# Mark everything as an integration test.
|
|
|
|
if not is_already_integration:
|
|
|
|
item.add_marker(pytest.mark.integration)
|