You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had encounter a problem when reusing a global WorkflowEnvironment defined as a pytest fixture resulted in time-skipping not working. I followed the common practice of define a @pytest.fixture(scope="session") which invoked WorkflowEnvironment.start_time_skipping but time-skipping wasn't happening, i.e. calls to env.sleep(x) were effectively behaving as blocking call. I debugged and realized the source of the blocking was https://github.com/temporalio/sdk-python/blob/a1b5d653fa712d35194e275295c5ec9c3721ecc9/temporalio/testing/_workflow.py#L424
Your recommended content
I naively adopted a well-known pattern (using pytest fixtures with scope="session" for test infrastructure) that lead me in the wrong direction. I think we should make clear in the documentation that tests should be written like so:
def test1():
with WorkflowEnvironment.start_time_skipping() as env:
pass
def test2():
with WorkflowEnvironment.start_time_skipping() as env:
pass
and the idea of caching the workflow environment, although natural, can lead to a bad outcome.
I am happy to contribute this back to the docs and maybe a sample
The text was updated successfully, but these errors were encountered:
edmondop
changed the title
[ Documentation request ] Python: Pytest fixtures and WorkflowEnvironment
[ Documentation request ] Python: Improve docuemntation about how (not to) use Pytest fixtures session scope and WorkflowEnvironment
Sep 26, 2024
edmondop
changed the title
[ Documentation request ] Python: Improve docuemntation about how (not to) use Pytest fixtures session scope and WorkflowEnvironment
[ Documentation request ] Python: How (not to) use Pytest fixtures session scope and WorkflowEnvironment
Sep 26, 2024
Brief description
I had encounter a problem when reusing a global WorkflowEnvironment defined as a pytest fixture resulted in time-skipping not working. I followed the common practice of define a
@pytest.fixture(scope="session")
which invokedWorkflowEnvironment.start_time_skipping
but time-skipping wasn't happening, i.e. calls toenv.sleep(x)
were effectively behaving as blocking call. I debugged and realized the source of the blocking was https://github.com/temporalio/sdk-python/blob/a1b5d653fa712d35194e275295c5ec9c3721ecc9/temporalio/testing/_workflow.py#L424Your recommended content
I naively adopted a well-known pattern (using pytest fixtures with scope="session" for test infrastructure) that lead me in the wrong direction. I think we should make clear in the documentation that tests should be written like so:
and the idea of caching the workflow environment, although natural, can lead to a bad outcome.
I am happy to contribute this back to the docs and maybe a sample
The text was updated successfully, but these errors were encountered: