From 66d148123895f9e191e40e0e087b294a6a62a11f Mon Sep 17 00:00:00 2001 From: Tim Conley Date: Wed, 22 Oct 2025 09:32:15 -0700 Subject: [PATCH 1/2] Putting back pytest passthrough, plus a few new places --- tests/contrib/openai_agents/test_openai.py | 5 ++++- tests/contrib/openai_agents/test_openai_replay.py | 7 +++++-- tests/test_client.py | 6 +++++- tests/test_workflow.py | 7 +++++-- tests/worker/test_activity.py | 7 +++++-- tests/worker/test_interceptor.py | 7 +++++-- tests/worker/test_replayer.py | 7 +++++-- tests/worker/test_update_with_start.py | 7 +++++-- tests/worker/test_worker.py | 6 +++++- tests/worker/test_workflow.py | 6 +++++- tests/worker/workflow_sandbox/test_runner.py | 7 +++++-- 11 files changed, 54 insertions(+), 18 deletions(-) diff --git a/tests/contrib/openai_agents/test_openai.py b/tests/contrib/openai_agents/test_openai.py index 33e150cbf..c9993808b 100644 --- a/tests/contrib/openai_agents/test_openai.py +++ b/tests/contrib/openai_agents/test_openai.py @@ -18,7 +18,6 @@ import nexusrpc import pydantic -import pytest from agents import ( Agent, AgentBase, @@ -114,6 +113,10 @@ from tests.helpers import assert_eventually, new_worker from tests.helpers.nexus import create_nexus_endpoint, make_nexus_endpoint_name +# Passing through because Python <=3.12 has an import bug at +# https://github.com/python/cpython/issues/91351 +with workflow.unsafe.imports_passed_through(): + import pytest class StaticTestModel(TestModel): __test__ = False diff --git a/tests/contrib/openai_agents/test_openai_replay.py b/tests/contrib/openai_agents/test_openai_replay.py index 6db463392..655c2f52c 100644 --- a/tests/contrib/openai_agents/test_openai_replay.py +++ b/tests/contrib/openai_agents/test_openai_replay.py @@ -1,7 +1,6 @@ from pathlib import Path -import pytest - +from temporalio import workflow from temporalio.client import WorkflowHistory from temporalio.contrib.openai_agents import OpenAIAgentsPlugin from temporalio.worker import Replayer @@ -15,6 +14,10 @@ ToolsWorkflow, ) +# Passing through because Python <=3.12 has an import bug at +# https://github.com/python/cpython/issues/91351 +with workflow.unsafe.imports_passed_through(): + import pytest @pytest.mark.parametrize( "file_name", diff --git a/tests/test_client.py b/tests/test_client.py index 63dec2810..5f4a42287 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -7,7 +7,6 @@ from unittest import mock import google.protobuf.any_pb2 -import pytest from google.protobuf import json_format import temporalio.api.common.v1 @@ -102,6 +101,11 @@ KSWorkflowParams, ) +# Passing through because Python <=3.12 has an import bug at +# https://github.com/python/cpython/issues/91351 +with workflow.unsafe.imports_passed_through(): + import pytest + async def test_start_id_reuse( client: Client, worker: ExternalWorker, env: WorkflowEnvironment diff --git a/tests/test_workflow.py b/tests/test_workflow.py index f62f02b8a..028db8b1e 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -2,11 +2,14 @@ import itertools from typing import Any, Callable, Sequence, Set, Type, get_type_hints -import pytest - from temporalio import workflow from temporalio.common import RawValue, VersioningBehavior +# Passing through because Python <=3.12 has an import bug at +# https://github.com/python/cpython/issues/91351 +with workflow.unsafe.imports_passed_through(): + import pytest + class GoodDefnBase: @workflow.run diff --git a/tests/worker/test_activity.py b/tests/worker/test_activity.py index 203b89a5a..fb39749b8 100644 --- a/tests/worker/test_activity.py +++ b/tests/worker/test_activity.py @@ -17,8 +17,6 @@ from time import sleep from typing import Any, Callable, List, NoReturn, Optional, Sequence, Type -import pytest - import temporalio.api.workflowservice.v1 from temporalio import activity, workflow from temporalio.client import ( @@ -52,6 +50,11 @@ kitchen_sink_retry_policy, ) +# Passing through because Python <=3.12 has an import bug at +# https://github.com/python/cpython/issues/91351 +with workflow.unsafe.imports_passed_through(): + import pytest + _default_shared_state_manager = SharedStateManager.create_from_multiprocessing( multiprocessing.Manager() ) diff --git a/tests/worker/test_interceptor.py b/tests/worker/test_interceptor.py index 1cb6cd25d..2bed3bd27 100644 --- a/tests/worker/test_interceptor.py +++ b/tests/worker/test_interceptor.py @@ -3,8 +3,6 @@ from datetime import timedelta from typing import Any, Callable, List, NoReturn, Optional, Tuple, Type -import pytest - from temporalio import activity, workflow from temporalio.client import Client, WorkflowUpdateFailedError from temporalio.exceptions import ApplicationError, NexusOperationError @@ -32,6 +30,11 @@ from temporalio.worker._interceptor import StartNexusOperationInput from tests.helpers.nexus import create_nexus_endpoint, make_nexus_endpoint_name +# Passing through because Python <=3.12 has an import bug at +# https://github.com/python/cpython/issues/91351 +with workflow.unsafe.imports_passed_through(): + import pytest + interceptor_traces: List[Tuple[str, Any]] = [] diff --git a/tests/worker/test_replayer.py b/tests/worker/test_replayer.py index e3ea8dcf7..f35f7efe3 100644 --- a/tests/worker/test_replayer.py +++ b/tests/worker/test_replayer.py @@ -8,8 +8,6 @@ from pathlib import Path from typing import Any, Dict, Optional, Type -import pytest - from temporalio import activity, workflow from temporalio.client import Client, WorkflowFailureError, WorkflowHistory from temporalio.exceptions import ApplicationError @@ -29,6 +27,11 @@ SignalsActivitiesTimersUpdatesTracingWorkflow, ) +# Passing through because Python <=3.12 has an import bug at +# https://github.com/python/cpython/issues/91351 +with workflow.unsafe.imports_passed_through(): + import pytest + @activity.defn async def say_hello(name: str) -> str: diff --git a/tests/worker/test_update_with_start.py b/tests/worker/test_update_with_start.py index 044307a7b..ce943f6a1 100644 --- a/tests/worker/test_update_with_start.py +++ b/tests/worker/test_update_with_start.py @@ -8,8 +8,6 @@ from typing import Any, Mapping, Optional, Union from unittest.mock import patch -import pytest - import temporalio.api.common.v1 import temporalio.api.workflowservice.v1 from temporalio import activity, workflow @@ -35,6 +33,11 @@ new_worker, ) +# Passing through because Python <=3.12 has an import bug at +# https://github.com/python/cpython/issues/91351 +with workflow.unsafe.imports_passed_through(): + import pytest + @activity.defn async def activity_called_by_update() -> None: diff --git a/tests/worker/test_worker.py b/tests/worker/test_worker.py index 32f27f631..362ced446 100644 --- a/tests/worker/test_worker.py +++ b/tests/worker/test_worker.py @@ -8,7 +8,6 @@ from urllib.request import urlopen import nexusrpc -import pytest import temporalio.api.enums.v1 import temporalio.nexus @@ -60,6 +59,11 @@ ) from tests.helpers.nexus import create_nexus_endpoint, make_nexus_endpoint_name +# Passing through because Python <=3.12 has an import bug at +# https://github.com/python/cpython/issues/91351 +with workflow.unsafe.imports_passed_through(): + import pytest + def test_load_default_worker_binary_id(): # Just run it twice and confirm it didn't change diff --git a/tests/worker/test_workflow.py b/tests/worker/test_workflow.py index da335635b..da069bfd2 100644 --- a/tests/worker/test_workflow.py +++ b/tests/worker/test_workflow.py @@ -38,7 +38,6 @@ from urllib.request import urlopen import pydantic -import pytest from google.protobuf.timestamp_pb2 import Timestamp from typing_extensions import Literal, Protocol, runtime_checkable @@ -150,6 +149,11 @@ external_wait_cancel, ) +# Passing through because Python <=3.12 has an import bug at +# https://github.com/python/cpython/issues/91351 +with workflow.unsafe.imports_passed_through(): + import pytest + @workflow.defn class HelloWorkflow: diff --git a/tests/worker/workflow_sandbox/test_runner.py b/tests/worker/workflow_sandbox/test_runner.py index 73a49c420..c66e8583d 100644 --- a/tests/worker/workflow_sandbox/test_runner.py +++ b/tests/worker/workflow_sandbox/test_runner.py @@ -13,8 +13,6 @@ from enum import IntEnum from typing import Callable, Dict, List, Optional, Sequence, Set, Type -import pytest - from temporalio import activity, workflow from temporalio.client import Client, WorkflowFailureError, WorkflowHandle from temporalio.exceptions import ApplicationError @@ -29,6 +27,11 @@ from tests.worker.workflow_sandbox.testmodules import stateful_module from tests.worker.workflow_sandbox.testmodules.proto import SomeMessage +# Passing through because Python <=3.12 has an import bug at +# https://github.com/python/cpython/issues/91351 +with workflow.unsafe.imports_passed_through(): + import pytest + global_state = ["global orig"] # We just access os.name in here to show we _can_. It's access-restricted at # runtime only From f427f8cb55a7da2b2dea76bd8b913f6786cdff74 Mon Sep 17 00:00:00 2001 From: Tim Conley Date: Wed, 22 Oct 2025 10:06:26 -0700 Subject: [PATCH 2/2] Linting --- tests/contrib/openai_agents/test_openai.py | 1 + tests/contrib/openai_agents/test_openai_replay.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/contrib/openai_agents/test_openai.py b/tests/contrib/openai_agents/test_openai.py index c9993808b..731515c44 100644 --- a/tests/contrib/openai_agents/test_openai.py +++ b/tests/contrib/openai_agents/test_openai.py @@ -118,6 +118,7 @@ with workflow.unsafe.imports_passed_through(): import pytest + class StaticTestModel(TestModel): __test__ = False responses: list[ModelResponse] = [] diff --git a/tests/contrib/openai_agents/test_openai_replay.py b/tests/contrib/openai_agents/test_openai_replay.py index 655c2f52c..68aa7405e 100644 --- a/tests/contrib/openai_agents/test_openai_replay.py +++ b/tests/contrib/openai_agents/test_openai_replay.py @@ -19,6 +19,7 @@ with workflow.unsafe.imports_passed_through(): import pytest + @pytest.mark.parametrize( "file_name", [