Skip to content

Commit 7ef37f6

Browse files
committed
Improve docstring
1 parent b226d90 commit 7ef37f6

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

temporalio/activity.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,23 @@ def wait_sync(self, timeout: Optional[float] = None) -> None:
279279
def client() -> Client:
280280
"""Return a Temporal Client for use in the current activity.
281281
282+
The client is only available in `async def` activities.
283+
284+
In tests it is not available automatically, but you can pass a client when creating a
285+
:py:class:`temporalio.testing.ActivityEnvironment`.
286+
282287
Returns:
283288
:py:class:`temporalio.client.Client` for use in the current activity.
284289
285290
Raises:
286-
RuntimeError: When not in an activity.
291+
RuntimeError: When the client is not available.
287292
"""
288293
client = _Context.current().client
289294
if not client:
290295
raise RuntimeError(
291-
"No client available. The client is only available in async "
292-
"(i.e. `async def`) activities; not in sync (i.e. `def`) activities. "
293-
"In tests you can pass a client when creating ActivityEnvironment."
296+
"No client available. The client is only available in `async def` "
297+
"activities; not in `def` activities. In tests you can pass a "
298+
"client when creating ActivityEnvironment."
294299
)
295300
return client
296301

tests/worker/test_activity.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ async def get_name(name: str) -> str:
9797
async def test_client_available_in_async_activities(
9898
client: Client, worker: ExternalWorker
9999
):
100-
with pytest.raises(RuntimeError) as err:
100+
with pytest.raises(RuntimeError, match="Not in activity context"):
101101
activity.client()
102-
assert str(err.value) == "Not in activity context"
103102

104103
captured_client: Optional[Client] = None
105104

@@ -120,8 +119,8 @@ async def test_client_not_available_in_sync_activities(
120119
@activity.defn
121120
def some_activity() -> None:
122121
with pytest.raises(
123-
RuntimeError, match="The client is only available in async"
124-
) as err:
122+
RuntimeError, match="The client is only available in `async def`"
123+
):
125124
activity.client()
126125
nonlocal saw_error
127126
saw_error = True

0 commit comments

Comments
 (0)