Update documentation for setupAll and teardownAll

This commit is contained in:
Mark Spanbroek 2022-03-01 09:25:15 +01:00
parent c4b23d73a9
commit 1ecce5d1a6
2 changed files with 13 additions and 10 deletions

View File

@ -33,14 +33,6 @@ proc someAsyncProc {.async.} =
suite "test async proc":
setupAll:
# invoke await in the suite setup:
await someAsyncProc()
teardownAll:
# invoke await in the suite teardown:
await someAsyncProc()
setup:
# invoke await in each test setup:
await someAsyncProc()
@ -55,6 +47,17 @@ suite "test async proc":
```
setupAll and teardownAll
------------------------
The `setup` and `teardown` code runs before and after every test, just like the
standard [unittest][1] module. In addition we provide `setupAll` and
`teardownAll`. The `setupAll` code runs once before all tests in the suite, and
the `teardownAll` runs once after all tests in the suite. Use these only as a
last resort when setting up the test environment is very costly. Be careful that
the tests do not modify the environment that you set up, lest you introduce
dependencies between tests.
Unittest2
---------

View File

@ -2,12 +2,12 @@ template suite*(name, body) =
suite name:
# Runs before all tests in the suite
## Runs before all tests in the suite
template setupAll(setupAllBody) {.used.} =
let b = proc {.async.} = setupAllBody
waitFor b()
# Runs after all tests in the suite
## Runs after all tests in the suite
template teardownAll(teardownAllBody) {.used.} =
template teardownAllIMPL: untyped {.inject.} =
let a = proc {.async.} = teardownAllBody