Skip to content

Commit

Permalink
Change test harness example to session scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Apr 20, 2022
1 parent 5fd646b commit 1e5c255
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 1e5c255

Please sign in to comment.