class WorkflowEnvironment: (source)
Known subclasses: temporalio.testing._workflow._HasAServer
Constructors: WorkflowEnvironment.from_client(client), WorkflowEnvironment.start_local(namespace, data_converter, interceptors, plugins, ...), WorkflowEnvironment.start_time_skipping(data_converter, interceptors, plugins, default_workflow_query_reject_condition, ...), WorkflowEnvironment.start_time_skipping_v2(ts_config, **kwargs), WorkflowEnvironment(client)
Workflow environment for testing workflows.
Most developers will want to use one of these static methods:
start_local: start a local, full-featured Temporal serverstart_time_skipping_v2: start a local, full-featured Temporal server with time-skipping enabledstart_time_skipping: start the older, featured-limited Java test serverfrom_client: use an existing server
This environment is an async context manager, so it can be used with async
with to make sure it shuts down properly. Otherwise, shutdown
can be manually called.
To use the environment, simply use the client on it.
Workflows invoked on the workflow environment are automatically configured to have assert failures fail the workflow with the assertion error.
| Class Method | from |
Create a workflow environment from the given client. |
| Async Class Method | start |
Start a full Temporal server locally, downloading if necessary. |
| Async Class Method | start |
Start a V1 time skipping workflow environment. |
| Async Class Method | start |
Start a local Temporal server with per-workflow time skipping enabled. |
| Async Method | __aenter__ |
Noop for async with support. |
| Async Method | __aexit__ |
For async with support to just call shutdown. |
| Method | __init__ |
Create a workflow environment from a client. |
| Method | auto |
Disable V1's SDK-driven auto-unlock-on-result-await for the block. |
| Async Method | connect |
Create another client connected to this environment. |
| Async Method | create |
Create a Nexus endpoint with the given name and task queue. |
| Async Method | delete |
Delete a Nexus endpoint. |
| Async Method | fast |
Fast-forward this workflow's virtual clock by duration, and wait for it to complete. |
| Async Method | get |
Get the current time known to this environment. |
| Async Method | get |
Fetch a workflow's TimeSkippingInfo via DescribeWorkflowExecution. |
| Async Method | shutdown |
Shut down this environment. |
| Async Method | sleep |
Sleep in this environment. |
| Method | with |
Suspend V2 time-skipping config stamping on newly-started workflows within the block. |
| Property | client |
Client to this environment. |
| Property | supports |
Whether this environment supports either V1 or V2 time skipping. |
| Property | supports |
True if this environment uses the V1 Java time-skipping server (which has limited server features). |
| Property | supports |
True if this environment uses the V2 time-skipping server. |
| Instance Variable | _client |
Undocumented |
Create a workflow environment from the given client.
supports_time_skipping_v1 and supports_time_skipping_v2
will both return False for this environment.
sleep will sleep the actual amount of time and
get_current_time will return the current time.
| Parameters | |
client:temporalio.client.Client | The client to use for the environment. |
| Returns | |
WorkflowEnvironment | The workflow environment that runs against the given client. |
str = 'default', data_converter: temporalio.converter.DataConverter = temporalio.converter.DataConverter.default, interceptors: Sequence[ temporalio.client.Interceptor] = [], plugins: Sequence[ temporalio.client.Plugin] = [], default_workflow_query_reject_condition: None | temporalio.common.QueryRejectCondition = None, retry_config: temporalio.service.RetryConfig | None = None, rpc_metadata: Mapping[ str, str | bytes] = {}, identity: str | None = None, tls: bool | temporalio.service.TLSConfig = False, ip: str = '127.0.0.1', port: int | None = None, download_dest_dir: str | None = None, ui: bool = False, runtime: temporalio.runtime.Runtime | None = None, search_attributes: Sequence[ temporalio.common.SearchAttributeKey] = (), dev_server_existing_path: str | None = None, dev_server_database_filename: str | None = None, dev_server_log_format: str = 'pretty', dev_server_log_level: str | None = 'warn', dev_server_download_version: str = 'default', dev_server_extra_args: Sequence[ str] = [], dev_server_download_ttl: timedelta | None = None, dev_server_startup_timeout: timedelta | None = None, ui_port: int | None = None) -> WorkflowEnvironment:
(source)
¶
Start a full Temporal server locally, downloading if necessary.
This environment is good for testing full server capabilities, but does
not support time skipping like start_time_skipping or
start_time_skipping_v2 do. supports_time_skipping_v1
and supports_time_skipping_v2 will both return False for
this environment. sleep will sleep the actual amount of time
and get_current_time will return the current time.
Internally, this uses the Temporal CLI dev server from https://github.com/temporalio/cli. This is a self-contained binary for Temporal using Sqlite persistence. This call will download the CLI to a temporary directory by default if it has not already been downloaded before and dev_server_existing_path is not set.
In the future, the dev server implementation may be changed to another implementation. Therefore, all dev_server_ prefixed parameters are dev-server specific and may not apply to newer versions.
| Parameters | |
namespace:str | Namespace name to use for this environment. |
datatemporalio.converter.DataConverter | See parameter of the same name on
temporalio.client.Client.connect. |
interceptors:Sequence[ | See parameter of the same name on
temporalio.client.Client.connect. |
plugins:Sequence[ | Undocumented |
defaultNone | temporalio.common.QueryRejectCondition | See parameter of the same
name on temporalio.client.Client.connect. |
retrytemporalio.service.RetryConfig | None | See parameter of the same name on
temporalio.client.Client.connect. |
rpcMapping[ | See parameter of the same name on
temporalio.client.Client.connect. |
identity:str | None | See parameter of the same name on
temporalio.client.Client.connect. |
tls:bool | temporalio.service.TLSConfig | See parameter of the same name on
temporalio.client.Client.connect. |
ip:str | IP address to bind to, or 127.0.0.1 by default. |
port:int | None | Port number to bind to, or an OS-provided port by default. |
downloadstr | None | Directory to download binary to if a download is needed. If unset, this is the system's temporary directory. |
ui:bool | If True, will start a UI in the dev server. |
runtime:temporalio.runtime.Runtime | None | Specific runtime to use or default if unset. |
searchSequence[ | Search attributes to register with the dev server. |
devstr | None | Existing path to the CLI binary. If present, no download will be attempted to fetch the binary. |
devstr | None | Path to the Sqlite database to use for the dev server. Unset default means only in-memory Sqlite will be used. |
devstr | Log format for the dev server. |
devstr | None | Log level to use for the dev server. Default is warn, but if set to None this will translate the Python logger's level to a dev server log level. |
devstr | Specific CLI version to download. Defaults to default which downloads the version known to work best with this SDK. |
devSequence[ | Extra arguments for the CLI binary. |
devtimedelta | None | TTL for the downloaded CLI binary. If unset, it will be cached indefinitely. |
devtimedelta | None | Maximum time to wait for the dev server to become ready after spawning. Defaults to 5 seconds and does not include download time. |
uiint | None | UI port to use if UI is enabled. |
| Returns | |
WorkflowEnvironment | The started CLI dev server workflow environment. |
temporalio.converter.DataConverter = temporalio.converter.DataConverter.default, interceptors: Sequence[ temporalio.client.Interceptor] = [], plugins: Sequence[ temporalio.client.Plugin] = [], default_workflow_query_reject_condition: None | temporalio.common.QueryRejectCondition = None, retry_config: temporalio.service.RetryConfig | None = None, rpc_metadata: Mapping[ str, str | bytes] = {}, identity: str | None = None, port: int | None = None, download_dest_dir: str | None = None, runtime: temporalio.runtime.Runtime | None = None, test_server_existing_path: str | None = None, test_server_download_version: str = 'default', test_server_extra_args: Sequence[ str] = [], test_server_download_ttl: timedelta | None = None, test_server_startup_timeout: timedelta | None = None) -> WorkflowEnvironment:
(source)
¶
Start a V1 time skipping workflow environment.
This environment uses a legacy Java Temporal server which does not have feature parity with the full temporal server, and which is no longer getting new features.
By default, this environment will automatically skip to the next events
in time when a workflow's
temporalio.client.WorkflowHandle.result is awaited on (which
includes temporalio.client.Client.execute_workflow). Before
the result is awaited on, time can be manually skipped forward using
sleep. The currently known time can be obtained via
get_current_time.
Internally, this environment lazily downloads a test-server binary for
the current OS/arch into the temp directory if it is not already there.
Then the executable is started and will be killed when
shutdown is called (which is implicitly done if this is
started via
async with await WorkflowEnvironment.start_time_skipping()).
Users can reuse this environment for testing multiple independent
workflows, but not concurrently. Time skipping, which is automatically
done when awaiting a workflow result and manually done on
sleep, is global to the environment, not to the workflow
under test.
In the future, the test server implementation may be changed to another implementation. Therefore, all test_server_ prefixed parameters are test server specific and may not apply to newer versions.
| Parameters | |
datatemporalio.converter.DataConverter | See parameter of the same name on
temporalio.client.Client.connect. |
interceptors:Sequence[ | See parameter of the same name on
temporalio.client.Client.connect. |
plugins:Sequence[ | Undocumented |
defaultNone | temporalio.common.QueryRejectCondition | See parameter of the same
name on temporalio.client.Client.connect. |
retrytemporalio.service.RetryConfig | None | See parameter of the same name on
temporalio.client.Client.connect. |
rpcMapping[ | See parameter of the same name on
temporalio.client.Client.connect. |
identity:str | None | See parameter of the same name on
temporalio.client.Client.connect. |
port:int | None | Port number to bind to, or an OS-provided port by default. |
downloadstr | None | Directory to download binary to if a download is needed. If unset, this is the system's temporary directory. |
runtime:temporalio.runtime.Runtime | None | Specific runtime to use or default if unset. |
teststr | None | Existing path to the test server binary. If present, no download will be attempted to fetch the binary. |
teststr | Specific test server version to download. Defaults to default which downloads the version known to work best with this SDK. |
testSequence[ | Extra arguments for the test server binary. |
testtimedelta | None | TTL for the downloaded test server binary. If unset, it will be cached indefinitely. |
testtimedelta | None | Maximum time to wait for the test server to become ready after spawning. Defaults to 5 seconds and does not include download time. |
| Returns | |
WorkflowEnvironment | The started workflow environment with time skipping. |
TimeSkippingConfig = TimeSkippingConfig(), **kwargs: Any) -> WorkflowEnvironment:
(source)
¶
Start a local Temporal server with per-workflow time skipping enabled.
Warning
This API is experimental and unstable.
This environment is good for testing full server capabilities, and supports time skipping.
Equivalent to start_local plus a TimeSkipper wrap
on the client, which stamps time_skipping_config on every workflow
started via client and exposes fast_forward for
driving time skipping on running workflows. Each workflow has its own
virtual clock, unlike time-skipping V1.
See start_local for other keyword arguments.
temporalio.testing._workflow._HasAServerCreate a workflow environment from a client.
Most users would use a factory method instead.
temporalio.testing._workflow._V1WorkflowEnvironment, temporalio.testing._workflow._V2WorkflowEnvironmentDisable V1's SDK-driven auto-unlock-on-result-await for the block.
Only meaningful on time-skipping V1 envs. No-op on non-time-skipping
envs. Unsupported on V2 envs — use with_time_skipping_disabled
to suspend time-skipping config stamping on newly-started workflows
instead.
Create another client connected to this environment.
Namespace and connection credentials from this environment's client are
used by default.
Keyword arguments are forwarded to temporalio.client.Client.connect
and override those defaults.
str, task_queue: str) -> temporalio.api.nexus.v1.Endpoint:
(source)
¶
Create a Nexus endpoint with the given name and task queue.
| Parameters | |
endpointstr | The name of the Nexus endpoint to create. |
taskstr | The task queue to associate with the endpoint. |
| Returns | |
temporalio.api.nexus.v1.Endpoint | The created Nexus endpoint. |
Delete a Nexus endpoint.
| Parameters | |
endpoint:temporalio.api.nexus.v1.Endpoint | The Nexus endpoint to delete. |
temporalio.client.WorkflowHandle[ Any, Any], duration: timedelta | float | None = None, /) -> bool:
(source)
¶
temporalio.testing._workflow._V2WorkflowEnvironmentFast-forward this workflow's virtual clock by duration, and wait for it to complete.
Warning
This API is experimental and unstable.
Only supported on time-skipping V2 environments (created via
start_time_skipping_v2).
| Parameters | |
handle:temporalio.client.WorkflowHandle[ | Target workflow execution. |
duration:timedelta | float | None | One-shot advance by this amount (timedelta or seconds as a float). If None, skip time until workflow completion. |
| Returns | |
bool | True if the fast-forward transition is observed; False if the workflow terminates first. |
| Raises | |
RuntimeError | If called on a V1 or non-time-skipping environment. |
temporalio.client.WorkflowHandle[ Any, Any] | None = None) -> datetime:
(source)
¶
temporalio.testing._workflow._V1WorkflowEnvironment, temporalio.testing._workflow._V2WorkflowEnvironmentGet the current time known to this environment.
System time on non-time-skipping envs; the V1 test server's virtual clock on V1 envs. On V2 envs a handle is required — each workflow has its own virtual clock, read via TimeSkippingInfo.current_time.
| Parameters | |
handle:temporalio.client.WorkflowHandle[ | On V2 envs, the workflow whose virtual clock to read. Ignored on non-V2 envs. |
| Returns | |
datetime | Undocumented |
temporalio.client.WorkflowHandle[ Any, Any]) -> temporalio.api.common.v1.TimeSkippingInfo | None:
(source)
¶
temporalio.testing._workflow._V2WorkflowEnvironmentFetch a workflow's TimeSkippingInfo via DescribeWorkflowExecution.
Warning
This API is experimental and unstable.
Returns None if time skipping has never been enabled on the workflow.
Only supported on time-skipping V2 environments (created via
start_time_skipping_v2).
| Raises | |
RuntimeError | If called on a V1 or non-time-skipping environment. |
temporalio.testing._workflow._V1WorkflowEnvironment, temporalio.testing._workflow._V2WorkflowEnvironmentSleep in this environment.
This awaits a regular asyncio.sleep in regular environments,
or manually skips time in time-skipping environments.
temporalio.testing._workflow._V2WorkflowEnvironmentSuspend V2 time-skipping config stamping on newly-started workflows within the block.
Warning
This API is experimental and unstable.
Workflows started via client during the block do not receive
a time_skipping_config on their start request. Existing workflows
are unaffected. No-op on non-V2 environments.
temporalio.testing._workflow._V1WorkflowEnvironmentTrue if this environment uses the V1 Java time-skipping server (which has limited server features).
temporalio.testing._workflow._V2WorkflowEnvironmentTrue if this environment uses the V2 time-skipping server.
Warning
This API is experimental and unstable.
