Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Documentation request ] Python: How (not to) use Pytest fixtures session scope and WorkflowEnvironment #3111

Open
edmondop opened this issue Sep 26, 2024 · 0 comments

Comments

@edmondop
Copy link

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 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

@edmondop 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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant