Skip to content

Commit

Permalink
Merge pull request #1687 from PrefectHQ/session-test-harness
Browse files Browse the repository at this point in the history
Change test harness example to session scoped
  • Loading branch information
zanieb authored Apr 20, 2022
2 parents 976f918 + 1e5c255 commit 2455e51
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docs/tutorials/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ from prefect.utilities.testing import prefect_test_harness

from my_flows import my_favorite_function

@pytest.fixture(autouse=True)
@pytest.fixture(autouse=True, scope="session")
def prefect_test_fixture():
with prefect_test_harness():
yield

def test_my_favorite_function(prefect_test_fixture):
assert my_favorite_function().result() == 42
```
```

!!! note Session scoped fixture
In this example, the fixture is scoped to run once for the entire test session. In most cases, you will not need a clean database for each test and just want to isolate your test runs to a test database. Creating a new test database per test creates significant overhead, so we recommend scoping the fixture to the session. If you need to isolate some tests fully, you can use the test harness again to create a fresh database.

0 comments on commit 2455e51

Please sign in to comment.