Skip to content

Commit

Permalink
Update parameterised testing documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed May 17, 2021
1 parent 43286f3 commit d70c0ce
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion docs/source/guide/writing_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,36 @@ Parameterised testing
A parameterised test is where you define a single test that runs multiple times,
with different arguments being injected on each run.

Ward supports parameterised testing by allowing multiple fixtures or
The simplest way to parameterise tests in Ward is to write your test inside a loop. In each iteration of the loop,
you can pass different values into the test:

.. code-block:: python
for lhs, rhs, res in [
(1, 1, 2),
(2, 3, 5),
]:
@test("simple addition")
def _(left=lhs, right=rhs, result=res):
assert left + right == result
You can also make a reference to a fixture and Ward will resolve and inject it:

.. code-block:: python
@fixture
def five():
yield 5
for lhs, rhs, res in [
(1, 1, 2),
(2, 3, five),
]:
@test("simple addition")
def _(left=lhs, right=rhs, result=res):
assert left + right == result
Ward also supports parameterised testing by allowing multiple fixtures or
values to be bound as a keyword argument using the ```each`` function::

from ward import each, fixture, test
Expand Down

0 comments on commit d70c0ce

Please sign in to comment.