# Mock for temporal activity

**URL:** <https://community.temporal.io/t/mock-for-temporal-activity/11290>\
**Category:** Community Support\
**Tags:** python-sdk, testing\
**Created:** [March 7, 2024, 10:59pm UTC](https://community.temporal.io/t/mock-for-temporal-activity/11290 "2024-03-07T22:59:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmoya](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/mmoya/32/6833_2.png) [@mmoya](https://community.temporal.io/u/mmoya)\
**Post date:** [March 7, 2024, 10:59pm UTC](https://community.temporal.io/t/mock-for-temporal-activity/11290/1 "2024-03-07T22:59:42Z")

</div>

hello, we have a workflow that behaves like the snippet below where the activity and worker are computed on another k8s cluster than the orchestrator/workflow however both share the same temporal server, namespace and task queue. Thus we define `activities=[]` since it’s computed in another cluster. That said, I was wondering how I could create a mock test for a use case like this

```python
import asyncio
from dataclasses import dataclass
from datetime import timedelta

from temporalio import workflow
from temporalio.client import Client
from temporalio.worker import Worker

@dataclass
class ComposeGreetingInput:
    greeting: str
    name: str

@workflow.defn
class GreetingWorkflow:
    @workflow.run
    async def run(self, name: str) -> str:
        workflow.logger.info("Running workflow with parameter %s" % name)
        return await workflow.execute_activity(
            "compose_greeting",
            ComposeGreetingInput("Hello", name),
            start_to_close_timeout=timedelta(seconds=10),
        )

async def main():
    client = await Client.connect("localhost:7233")
    async with Worker(
        client,
        task_queue="hello-activity-task-queue",
        workflows=[GreetingWorkflow],
        activities=[],
    ):

        result = await client.execute_workflow(
            GreetingWorkflow.run,
            "World",
            id="hello-activity-workflow-id",
            task_queue="hello-activity-task-queue",
        )
        print(f"Result: {result}")

if __name__ == " __main__":
    asyncio.run(main())

```

---

<div class="post-metadata">

**Author:** ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)\
**Post date:** [March 7, 2024, 11:11pm UTC](https://community.temporal.io/t/mock-for-temporal-activity/11290/2 "2024-03-07T23:11:38Z")

</div>

> [@mmoya](#):
>
> That said, I was wondering how I could create a mock test for a use case like this

That code is creating a worker when you run the program. Since you create the worker in your test, you can set whatever activities you want on that worker unrelated to this `main` worker. See [the sample test](https://github.com/temporalio/samples-python/blob/4303a9b15f4ddc4cd770bc0ba33afef90a25d3ae/tests/hello/hello_activity_test.py#L31-L49).

---

<div class="post-metadata">

**Author:** ![mmoya](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/mmoya/32/6833_2.png) [@mmoya](https://community.temporal.io/u/mmoya)\
**Post date:** [March 12, 2024, 8:34pm UTC](https://community.temporal.io/t/mock-for-temporal-activity/11290/3 "2024-03-12T20:34:09Z")

</div>

thank you!

---

<div class="post-metadata">

**Author:** ![arxliu](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@arxliu](https://community.temporal.io/u/arxliu)\
**Post date:** [January 27, 2025, 7:59pm UTC](https://community.temporal.io/t/mock-for-temporal-activity/11290/4 "2025-01-27T19:59:48Z")

</div>

Hi, my workflow executes an activity in a class, like the following. If the activity called was not given a name at the time of definition, can the `MyGreetingActivity.compose_greeting` be represented in the mock?

```py
class GreetingWorkflow:
    @workflow.run
    async def run(self, name: str) -> str:
        return await workflow.execute_activity_method(
            MyGreetingActivity.compose_greeting, # use the method name instead of the activity name
            ComposeGreetingInput("Hello", name),
            start_to_close_timeout=timedelta(seconds=10),
        )

```
