Basic scenario with when/then and a JSON attachment
billing
happy-path
Given
a coffee machine
When
I insert $2
Then
I get a coffee
Plain text attachment
billing
Given
a coffee machine
When
I print the receipt
Then
the receipt is recorded verbatim
Generator fixture with teardown
Given
a database connection
When
I run a query
Then
the connection is open and the query was logged
Not enough money
billing
edge-case
Given
a coffee machine
When
I insert $1
Then
I don't get a coffee
Helper functions can record their own steps
billing
Given
a coffee machine
When
I insert $2
validating coin... accepted
updating balance
Then
the coin is accepted
a coffee is dispensed
the machine state is consistent
Top-level `given` block and deeply nested steps
billing
Given
a coffee machine
a loyalty card with 5 points
When
I place a large order
I select 3 coffees
I apply loyalty discount
validating loyalty card
calculating discount
Then
the order is processed correctly
the coffee count is updated
the loyalty points are deducted
the remaining points are valid
the machine state is consistent
Failure rendering (intentionally failing)
Given
a coffee machine
Then
the machine has 20 coffees
.nox\examples\Lib\site-packages\_pytest\runner.py:353: in from_call
result: TResult | None = func()
^^^^^^
.nox\examples\Lib\site-packages\_pytest\runner.py:245: in <lambda>
lambda: runtest_hook(item=item, **kwds),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.nox\examples\Lib\site-packages\pluggy\_hooks.py:512: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.nox\examples\Lib\site-packages\pluggy\_manager.py:120: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.nox\examples\Lib\site-packages\_pytest\logging.py:850: in pytest_runtest_call
yield
.nox\examples\Lib\site-packages\_pytest\capture.py:900: in pytest_runtest_call
return (yield)
^^^^^
.nox\examples\Lib\site-packages\_pytest\skipping.py:268: in pytest_runtest_call
return (yield)
^^^^^
.nox\examples\Lib\site-packages\_pytest\runner.py:179: in pytest_runtest_call
item.runtest()
.nox\examples\Lib\site-packages\_pytest\python.py:1720: in runtest
self.ihook.pytest_pyfunc_call(pyfuncitem=self)
.nox\examples\Lib\site-packages\pluggy\_hooks.py:512: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.nox\examples\Lib\site-packages\pluggy\_manager.py:120: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.nox\examples\Lib\site-packages\_pytest\python.py:166: in pytest_pyfunc_call
result = testfunction(**testargs)
^^^^^^^^^^^^^^^^^^^^^^^^
src\pytest_given\decorators.py:91: in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
examples\test_examples.py:121: in test_failing
assert machine['coffees'] == 20
E assert 10 == 20
Parameterized test (renders as a parameter table)
billing
Given
a coffee machine
When
I insert ${euros}
Then
can_buy is {expect}
| euros | expect | status |
|---|---|---|
| 1 | False | โ |
| 2 | True | โ |
| 3 | True | โ |