diff --git a/integration_tests/python_modules/dagster-k8s-test-infra/dagster_k8s_test_infra/helm.py b/integration_tests/python_modules/dagster-k8s-test-infra/dagster_k8s_test_infra/helm.py index 2e6ce39e3eccb..60d45c2abfa7b 100644 --- a/integration_tests/python_modules/dagster-k8s-test-infra/dagster_k8s_test_infra/helm.py +++ b/integration_tests/python_modules/dagster-k8s-test-infra/dagster_k8s_test_infra/helm.py @@ -13,11 +13,14 @@ import yaml from dagster._utils import find_free_port, git_repository_root from dagster._utils.merger import merge_dicts -from dagster_aws_tests.aws_credential_test_utils import get_aws_creds +from dagster_aws.utils import ensure_dagster_aws_tests_import from dagster_k8s.client import DagsterKubernetesClient from .integration_utils import IS_BUILDKITE, check_output, get_test_namespace, image_pull_policy +ensure_dagster_aws_tests_import() +from dagster_aws_tests.aws_credential_test_utils import get_aws_creds + TEST_AWS_CONFIGMAP_NAME = "test-aws-env-configmap" TEST_CONFIGMAP_NAME = "test-env-configmap" TEST_OTHER_CONFIGMAP_NAME = "test-other-env-configmap" diff --git a/python_modules/dagster-graphql/dagster_graphql/test/utils.py b/python_modules/dagster-graphql/dagster_graphql/test/utils.py index 69768d9ba458c..7b8f9c2964781 100644 --- a/python_modules/dagster-graphql/dagster_graphql/test/utils.py +++ b/python_modules/dagster-graphql/dagster_graphql/test/utils.py @@ -1,5 +1,7 @@ import asyncio +import sys from contextlib import contextmanager +from pathlib import Path from typing import Any, Dict, Iterator, Mapping, Optional, Sequence import dagster._check as check @@ -11,6 +13,7 @@ from dagster._core.workspace.load_target import PythonFileTarget from typing_extensions import Protocol, TypeAlias, TypedDict +from dagster_graphql import __file__ as dagster_graphql_init_py from dagster_graphql.schema import create_schema @@ -222,3 +225,11 @@ def infer_resource_selector(graphql_context: WorkspaceRequestContext, name: str) selector = infer_repository_selector(graphql_context) selector = {**selector, **{"resourceName": name}} return selector + + +def ensure_dagster_graphql_tests_import() -> None: + dagster_package_root = (Path(dagster_graphql_init_py) / ".." / "..").resolve() + assert ( + dagster_package_root / "dagster_graphql_tests" + ).exists(), "Could not find dagster_graphql_tests where expected" + sys.path.append(dagster_package_root.as_posix()) diff --git a/python_modules/dagster-graphql/dagster_graphql_tests/graphql/test_asset_backfill.py b/python_modules/dagster-graphql/dagster_graphql_tests/graphql/test_asset_backfill.py index 961ceec924cd5..18704564a2c27 100644 --- a/python_modules/dagster-graphql/dagster_graphql_tests/graphql/test_asset_backfill.py +++ b/python_modules/dagster-graphql/dagster_graphql_tests/graphql/test_asset_backfill.py @@ -15,7 +15,7 @@ ) from dagster._core.execution.asset_backfill import AssetBackfillData from dagster._core.instance import DagsterInstance -from dagster._core.test_utils import instance_for_test +from dagster._core.test_utils import ensure_dagster_tests_import, instance_for_test from dagster_graphql.client.query import LAUNCH_PARTITION_BACKFILL_MUTATION from dagster_graphql.test.utils import ( GqlResult, @@ -23,6 +23,8 @@ execute_dagster_graphql, main_repo_location_name, ) + +ensure_dagster_tests_import() from dagster_tests.definitions_tests.auto_materialize_tests.scenarios.asset_graphs import ( root_assets_different_partitions_same_downstream, ) diff --git a/python_modules/dagster-test/dagster_test_tests/test_toys.py b/python_modules/dagster-test/dagster_test_tests/test_toys.py index fe94ca711acf3..815e7992d7ea0 100644 --- a/python_modules/dagster-test/dagster_test_tests/test_toys.py +++ b/python_modules/dagster-test/dagster_test_tests/test_toys.py @@ -16,7 +16,7 @@ from dagster._core.definitions.unresolved_asset_job_definition import define_asset_job from dagster._core.events import DagsterEventType from dagster._core.storage.fs_io_manager import fs_io_manager -from dagster._core.test_utils import instance_for_test +from dagster._core.test_utils import ensure_dagster_tests_import, instance_for_test from dagster._utils import file_relative_path from dagster._utils.temp_file import get_temp_dir from dagster_test.toys.branches import branch @@ -39,6 +39,8 @@ from dagster_test.toys.sensors import get_toys_sensors from dagster_test.toys.sleepy import sleepy from dagster_test.toys.software_defined_assets import software_defined_assets + +ensure_dagster_tests_import() from dagster_tests.execution_tests.engine_tests.test_step_delegating_executor import ( test_step_delegating_executor, ) diff --git a/python_modules/dagster/dagster/_core/code_pointer.py b/python_modules/dagster/dagster/_core/code_pointer.py index 82b68ecf70917..6af8ded1ba30c 100644 --- a/python_modules/dagster/dagster/_core/code_pointer.py +++ b/python_modules/dagster/dagster/_core/code_pointer.py @@ -127,7 +127,6 @@ def load_python_module( list(remove_from_path_fn()) if remove_from_path_fn else [] ) # hook for tests remove_paths.insert(0, sys.path[0]) # remove the script path - with alter_sys_path( to_add=([working_directory] if working_directory else []), to_remove=remove_paths ): diff --git a/python_modules/dagster/dagster/_core/test_utils.py b/python_modules/dagster/dagster/_core/test_utils.py index fd1bb499c3b70..25e2b09552bba 100644 --- a/python_modules/dagster/dagster/_core/test_utils.py +++ b/python_modules/dagster/dagster/_core/test_utils.py @@ -7,6 +7,7 @@ from collections import defaultdict from concurrent.futures import Future, ThreadPoolExecutor from contextlib import contextmanager +from pathlib import Path from signal import Signals from threading import Event from typing import ( @@ -32,6 +33,7 @@ from dagster import ( Permissive, Shape, + __file__ as dagster_init_py, _check as check, fs_io_manager, ) @@ -708,3 +710,11 @@ def raise_exception_on_warnings(): if sys.version_info >= (3, 12): # pendulum sometimes raises DeprecationWarning on python3.12 warnings.filterwarnings("ignore", category=DeprecationWarning, module="pendulum") + + +def ensure_dagster_tests_import() -> None: + dagster_package_root = (Path(dagster_init_py) / ".." / "..").resolve() + assert ( + dagster_package_root / "dagster_tests" + ).exists(), "Could not find dagster_tests where expected" + sys.path.append(dagster_package_root.as_posix()) diff --git a/python_modules/dagster/dagster_tests/cli_tests/test_api_commands.py b/python_modules/dagster/dagster_tests/cli_tests/test_api_commands.py index 6d51ca8c48ea0..aef1ee2f9ab52 100644 --- a/python_modules/dagster/dagster_tests/cli_tests/test_api_commands.py +++ b/python_modules/dagster/dagster_tests/cli_tests/test_api_commands.py @@ -9,9 +9,15 @@ from dagster._core.execution.retries import RetryState from dagster._core.execution.stats import RunStepKeyStatsSnapshot from dagster._core.host_representation import JobHandle -from dagster._core.test_utils import create_run_for_test, environ, instance_for_test +from dagster._core.test_utils import ( + create_run_for_test, + ensure_dagster_tests_import, + environ, + instance_for_test, +) from dagster._serdes import serialize_value +ensure_dagster_tests_import() from dagster_tests.api_tests.utils import get_bar_repo_handle, get_foo_job_handle diff --git a/python_modules/libraries/dagster-aws/dagster_aws/utils/__init__.py b/python_modules/libraries/dagster-aws/dagster_aws/utils/__init__.py index 196512649ba5c..b53523cfee36c 100644 --- a/python_modules/libraries/dagster-aws/dagster_aws/utils/__init__.py +++ b/python_modules/libraries/dagster-aws/dagster_aws/utils/__init__.py @@ -1,3 +1,5 @@ +import sys +from pathlib import Path from typing import Optional, TypeVar import dagster._check as check @@ -7,6 +9,8 @@ from packaging import version from pydantic import Field +from dagster_aws import __file__ as dagster_aws_init_py + def construct_boto_client_retry_config(max_attempts): check.int_param(max_attempts, "max_attempts") @@ -36,3 +40,11 @@ class ResourceWithBoto3Configuration(ConfigurableResource): profile_name: Optional[str] = Field( default=None, description="Specifies a profile to connect that session" ) + + +def ensure_dagster_aws_tests_import() -> None: + dagster_package_root = (Path(dagster_aws_init_py) / ".." / "..").resolve() + assert ( + dagster_package_root / "dagster_aws_tests" + ).exists(), "Could not find dagster_aws_tests where expected" + sys.path.append(dagster_package_root.as_posix()) diff --git a/python_modules/libraries/dagster-aws/dagster_aws_tests/s3_tests/test_compute_log_manager.py b/python_modules/libraries/dagster-aws/dagster_aws_tests/s3_tests/test_compute_log_manager.py index 56db8a1e2395e..35f173065e581 100644 --- a/python_modules/libraries/dagster-aws/dagster_aws_tests/s3_tests/test_compute_log_manager.py +++ b/python_modules/libraries/dagster-aws/dagster_aws_tests/s3_tests/test_compute_log_manager.py @@ -13,8 +13,10 @@ from dagster._core.storage.local_compute_log_manager import IO_TYPE_EXTENSION from dagster._core.storage.root import LocalArtifactStorage from dagster._core.storage.runs import SqliteRunStorage -from dagster._core.test_utils import environ, instance_for_test +from dagster._core.test_utils import ensure_dagster_tests_import, environ, instance_for_test from dagster_aws.s3 import S3ComputeLogManager + +ensure_dagster_tests_import() from dagster_tests.storage_tests.test_captured_log_manager import TestCapturedLogManager HELLO_WORLD = "Hello World" diff --git a/python_modules/libraries/dagster-azure/dagster_azure_tests/blob_tests/test_compute_log_manager.py b/python_modules/libraries/dagster-azure/dagster_azure_tests/blob_tests/test_compute_log_manager.py index ac405ab6b78e4..28443248fac9e 100644 --- a/python_modules/libraries/dagster-azure/dagster_azure_tests/blob_tests/test_compute_log_manager.py +++ b/python_modules/libraries/dagster-azure/dagster_azure_tests/blob_tests/test_compute_log_manager.py @@ -12,8 +12,10 @@ from dagster._core.storage.event_log import SqliteEventLogStorage from dagster._core.storage.root import LocalArtifactStorage from dagster._core.storage.runs import SqliteRunStorage -from dagster._core.test_utils import environ +from dagster._core.test_utils import ensure_dagster_tests_import, environ from dagster_azure.blob import AzureBlobComputeLogManager, FakeBlobServiceClient + +ensure_dagster_tests_import() from dagster_tests.storage_tests.test_captured_log_manager import TestCapturedLogManager HELLO_WORLD = "Hello World" diff --git a/python_modules/libraries/dagster-celery-docker/dagster_celery_docker_tests/conftest.py b/python_modules/libraries/dagster-celery-docker/dagster_celery_docker_tests/conftest.py index d8ddeebc007a3..d75c58584f859 100644 --- a/python_modules/libraries/dagster-celery-docker/dagster_celery_docker_tests/conftest.py +++ b/python_modules/libraries/dagster-celery-docker/dagster_celery_docker_tests/conftest.py @@ -1,4 +1,7 @@ import pytest +from dagster_aws.utils import ensure_dagster_aws_tests_import + +ensure_dagster_aws_tests_import() from dagster_aws_tests.aws_credential_test_utils import get_aws_creds diff --git a/python_modules/libraries/dagster-docker/dagster_docker_tests/conftest.py b/python_modules/libraries/dagster-docker/dagster_docker_tests/conftest.py index 66d5aa6e2c760..67f86c5180849 100644 --- a/python_modules/libraries/dagster-docker/dagster_docker_tests/conftest.py +++ b/python_modules/libraries/dagster-docker/dagster_docker_tests/conftest.py @@ -1,4 +1,7 @@ import pytest +from dagster_aws.utils import ensure_dagster_aws_tests_import + +ensure_dagster_aws_tests_import() from dagster_aws_tests.aws_credential_test_utils import get_aws_creds diff --git a/python_modules/libraries/dagster-gcp/dagster_gcp_tests/gcs_tests/test_compute_log_manager.py b/python_modules/libraries/dagster-gcp/dagster_gcp_tests/gcs_tests/test_compute_log_manager.py index 984f7279ae1f5..ed3ece018f1b6 100644 --- a/python_modules/libraries/dagster-gcp/dagster_gcp_tests/gcs_tests/test_compute_log_manager.py +++ b/python_modules/libraries/dagster-gcp/dagster_gcp_tests/gcs_tests/test_compute_log_manager.py @@ -15,11 +15,13 @@ from dagster._core.storage.event_log import SqliteEventLogStorage from dagster._core.storage.root import LocalArtifactStorage from dagster._core.storage.runs import SqliteRunStorage -from dagster._core.test_utils import environ, instance_for_test +from dagster._core.test_utils import ensure_dagster_tests_import, environ, instance_for_test from dagster_gcp.gcs import GCSComputeLogManager -from dagster_tests.storage_tests.test_captured_log_manager import TestCapturedLogManager from google.cloud import storage +ensure_dagster_tests_import() +from dagster_tests.storage_tests.test_captured_log_manager import TestCapturedLogManager + HELLO_WORLD = "Hello World" SEPARATOR = os.linesep if (os.name == "nt" and sys.version_info < (3,)) else "\n" EXPECTED_LOGS = [ diff --git a/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_daemon_cursor_storage.py b/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_daemon_cursor_storage.py index 267d73ad1ebfc..f2f9bf49f6b65 100644 --- a/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_daemon_cursor_storage.py +++ b/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_daemon_cursor_storage.py @@ -1,5 +1,8 @@ import pytest +from dagster._core.test_utils import ensure_dagster_tests_import from dagster_mysql.run_storage import MySQLRunStorage + +ensure_dagster_tests_import() from dagster_tests.storage_tests.utils.daemon_cursor_storage import TestDaemonCursorStorage diff --git a/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_event_log.py b/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_event_log.py index 8a74459827044..e5eb1668633af 100644 --- a/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_event_log.py +++ b/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_event_log.py @@ -4,8 +4,10 @@ import pytest import yaml from dagster._core.storage.event_log.base import EventLogCursor -from dagster._core.test_utils import instance_for_test +from dagster._core.test_utils import ensure_dagster_tests_import, instance_for_test from dagster_mysql.event_log import MySQLEventLogStorage + +ensure_dagster_tests_import() from dagster_tests.storage_tests.utils.event_log_storage import ( TestEventLogStorage, create_test_event_log_record, diff --git a/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_run_storage.py b/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_run_storage.py index 72415b04d607a..63d355c4d37b2 100644 --- a/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_run_storage.py +++ b/python_modules/libraries/dagster-mysql/dagster_mysql_tests/test_run_storage.py @@ -2,8 +2,10 @@ import pytest import yaml -from dagster._core.test_utils import environ, instance_for_test +from dagster._core.test_utils import ensure_dagster_tests_import, environ, instance_for_test from dagster_mysql.run_storage import MySQLRunStorage + +ensure_dagster_tests_import() from dagster_tests.storage_tests.utils.run_storage import TestRunStorage TestRunStorage.__test__ = False diff --git a/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_daemon_cursor_storage.py b/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_daemon_cursor_storage.py index f0b61864d41da..a4c4f1ee80237 100644 --- a/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_daemon_cursor_storage.py +++ b/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_daemon_cursor_storage.py @@ -1,5 +1,8 @@ import pytest +from dagster._core.test_utils import ensure_dagster_tests_import from dagster_postgres.run_storage import PostgresRunStorage + +ensure_dagster_tests_import() from dagster_tests.storage_tests.utils.daemon_cursor_storage import TestDaemonCursorStorage diff --git a/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_event_log.py b/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_event_log.py index 24fa2a360b1ff..3d7cebee2ebf0 100644 --- a/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_event_log.py +++ b/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_event_log.py @@ -3,8 +3,10 @@ import pytest import yaml from dagster._core.storage.event_log.base import EventLogCursor -from dagster._core.test_utils import instance_for_test +from dagster._core.test_utils import ensure_dagster_tests_import, instance_for_test from dagster_postgres.event_log import PostgresEventLogStorage + +ensure_dagster_tests_import() from dagster_tests.storage_tests.utils.event_log_storage import ( TestEventLogStorage, create_test_event_log_record, diff --git a/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_run_storage.py b/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_run_storage.py index 8480d2e40f9b9..153a17faeab64 100644 --- a/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_run_storage.py +++ b/python_modules/libraries/dagster-postgres/dagster_postgres_tests/test_run_storage.py @@ -1,7 +1,9 @@ import pytest import yaml -from dagster._core.test_utils import environ, instance_for_test +from dagster._core.test_utils import ensure_dagster_tests_import, environ, instance_for_test from dagster_postgres.run_storage import PostgresRunStorage + +ensure_dagster_tests_import() from dagster_tests.storage_tests.utils.run_storage import TestRunStorage