Module:
Tag:
Term:
Basic scenario with when/then and a JSON attachment
Given
a coffee machine
When
I insert $2
Then
I get a coffee
Plain text attachment
Given
a coffee machine
a printed receipt
When
the total line is read back
Then
it shows the $2.00 total
Generator fixture with teardown
Given
a database connection
When
I run a query
Then
the connection is open and the query was logged
Parametrized test (renders as a parameter table)
Expected to fail:
happy-hour pricing not implemented yet
Given
a coffee machine
When
I insert ${euros}
Then
the purchase is allowed: {expect}
| euros | expect | status |
|---|---|---|
| 1 | False | ✓ |
| 2 | True | ✓ |
| 3 | True | ✓ |
| 1.5 | True | ⊗ |
|
site-packages/_pytest/runner.py:361: in from_call
result: TResult | None = func()
^^^^^^
site-packages/_pytest/runner.py:250: in <lambda>
lambda: runtest_hook(item=item, **kwds),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/pluggy/_hooks.py:512: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/pluggy/_manager.py:120: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/_pytest/logging.py:865: in pytest_runtest_call
yield site-packages/_pytest/capture.py:900: in pytest_runtest_call
return (yield)
^^^^^
site-packages/_pytest/skipping.py:268: in pytest_runtest_call
return (yield)
^^^^^
site-packages/_pytest/runner.py:184: in pytest_runtest_call
item.runtest() site-packages/_pytest/python.py:1707: in runtest
self.ihook.pytest_pyfunc_call(pyfuncitem=self) site-packages/pluggy/_hooks.py:512: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/pluggy/_manager.py:120: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/_pytest/python.py:167: in pytest_pyfunc_call
result = testfunction(**testargs)
^^^^^^^^^^^^^^^^^^^^^^^^
examples/coffeeshop/test_coffeeshop.py:87: in test_pricing
assert purchase_allowed == expect E assert False == True |
||
Parametrize value surfaced as a given (Annotated)
Given
a coffee machine
an order for a {cup_size} ml cup
When
I brew the cup
Then
the machine has one fewer coffee
| cup_size |
|---|
| 200 |
| 350 |
T-string with a non-parametrize value (neutral highlight)
Given
a coffee machine
I have some coins in hand
When
I insert $5
Then
the machine has 9 coffees left
Brew {cup_size} ml (templated scenario name)
Given
a coffee machine
When
I brew a {cup_size} ml cup
Then
the tank is down {cup_size} ml and the machine has one fewer coffee
| cup_size |
|---|
| 200 |
| 300 |
Serve a 200 ml cup (one scenario per case) [200]
Given
a coffee machine
When
I order a 200 ml cup
Then
the tank is down 200 ml and the machine has one fewer coffee
Serve a 400 ml cup (one scenario per case) [400]
Given
a coffee machine
the barista reaches for a takeaway cup
When
I order a 400 ml cup
Then
the tank is down 400 ml and the machine has one fewer coffee
Brew a {flavor} coffee (per-case columns)
Given
a coffee machine
the machine is primed for {flavor}
When
I brew a {flavor} coffee
Then
the drink costs {price} euros
| flavor | brew log | price |
|---|---|---|
| vanilla | 2 | |
| mocha | 3 | |
Helper functions can record their own steps
Given
a coffee machine
When
I insert $2
Then
the coin is accepted
a coffee is dispensed
Top-level `given` block and deeply nested steps
Given
a coffee machine
a loyalty card with 5 points
When
I place a large order
Then
the order is processed correctly
the machine state is consistent
An expected error, narrated as when + then (when_then)
Given
a coffee machine
a machine that has sold its last coffee
When
a customer tries to buy a coffee
Then
the machine reports it is sold out
Many tags (the report collapses them behind a +N pill)
Given
a coffee machine
a loyalty card good for a $1 discount
When
I buy a coffee with the discount
Then
I pay $1
a coffee is dispensed
Failure rendering (intentionally failing)
Given
a coffee machine
Then
the machine has 20 coffees
site-packages/_pytest/runner.py:361: in from_call
result: TResult | None = func()
^^^^^^
site-packages/_pytest/runner.py:250: in <lambda>
lambda: runtest_hook(item=item, **kwds),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/pluggy/_hooks.py:512: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/pluggy/_manager.py:120: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/_pytest/logging.py:865: in pytest_runtest_call
yield
site-packages/_pytest/capture.py:900: in pytest_runtest_call
return (yield)
^^^^^
site-packages/_pytest/skipping.py:268: in pytest_runtest_call
return (yield)
^^^^^
site-packages/_pytest/runner.py:184: in pytest_runtest_call
item.runtest()
site-packages/_pytest/python.py:1707: in runtest
self.ihook.pytest_pyfunc_call(pyfuncitem=self)
site-packages/pluggy/_hooks.py:512: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/pluggy/_manager.py:120: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/_pytest/python.py:167: in pytest_pyfunc_call
result = testfunction(**testargs)
^^^^^^^^^^^^^^^^^^^^^^^^
examples/coffeeshop/test_coffeeshop.py:277: in test_failing
assert machine['coffees'] == 20
E assert 10 == 20
Skipped scenario rendering
Skipped:
demonstrates skipped status
Loyalty card earns a free coffee (planned feature)
Expected to fail:
loyalty cards not implemented yet
Given
a coffee machine
a loyalty card with nine stamps
When
I buy a coffee with the card
site-packages/_pytest/runner.py:361: in from_call
result: TResult | None = func()
^^^^^^
site-packages/_pytest/runner.py:250: in <lambda>
lambda: runtest_hook(item=item, **kwds),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/pluggy/_hooks.py:512: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/pluggy/_manager.py:120: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/_pytest/logging.py:865: in pytest_runtest_call
yield
site-packages/_pytest/capture.py:900: in pytest_runtest_call
return (yield)
^^^^^
site-packages/_pytest/skipping.py:268: in pytest_runtest_call
return (yield)
^^^^^
site-packages/_pytest/runner.py:184: in pytest_runtest_call
item.runtest()
site-packages/_pytest/python.py:1707: in runtest
self.ihook.pytest_pyfunc_call(pyfuncitem=self)
site-packages/pluggy/_hooks.py:512: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/pluggy/_manager.py:120: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
site-packages/_pytest/python.py:167: in pytest_pyfunc_call
result = testfunction(**testargs)
^^^^^^^^^^^^^^^^^^^^^^^^
examples/coffeeshop/test_coffeeshop.py:297: in test_loyalty_card_free_coffee
price_paid = pay_with_loyalty_card(machine, card)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
examples/coffeeshop/test_coffeeshop.py:288: in pay_with_loyalty_card
raise NotImplementedError('the machine does not read loyalty cards yet')
E NotImplementedError: the machine does not read loyalty cards yet
All cases skipped