| 1 |
.. _id.appendix.context_attributes: |
| 2 |
|
| 3 |
============================================================================== |
| 4 |
Context Attributes |
| 5 |
============================================================================== |
| 6 |
|
| 7 |
A context object (:class:`~behave.runner.Context`) is handed to |
| 8 |
|
| 9 |
* step definitions (step implementations) |
| 10 |
* behave hooks (:func:`before_all`, :func:`before_feature`, ..., :func:`after_all`) |
| 11 |
|
| 12 |
|
| 13 |
Behave Attributes |
| 14 |
------------------------- |
| 15 |
|
| 16 |
The :pypi:`behave` runner assigns a number of attributes to the context object |
| 17 |
during a test run. |
| 18 |
|
| 19 |
=============== ========= ============================================= ============================================================== |
| 20 |
Attribute Name Layer Type Description |
| 21 |
=============== ========= ============================================= ============================================================== |
| 22 |
config test run :class:`~behave.configuration.Configuration` Configuration that is used. |
| 23 |
aborted test run bool Set to true if test run is aborted by the user. |
| 24 |
failed test run bool Set to true if a step fails. |
| 25 |
feature feature :class:`~behave.model.Feature` Current feature. |
| 26 |
tags feature, list<:class:`~behave.model.Tag`> Effective tags of current feature, scenario, scenario outline. |
| 27 |
scenario |
| 28 |
active_outline scenario :class:`~behave.model.Row` Current row in a scenario outline (in examples table). |
| 29 |
outline |
| 30 |
scenario scenario :class:`~behave.model.Scenario` Current scenario. |
| 31 |
log_capture scenario :class:`~behave.log_capture.LoggingCapture` If logging capture is enabled. |
| 32 |
stdout_capture scenario :class:`~StringIO.StringIO` If stdout capture is enabled. |
| 33 |
stderr_capture scenario :class:`~StringIO.StringIO` If stderr capture is enabled. |
| 34 |
table step :class:`~behave.model.Table` Contains step's table, otherwise None. |
| 35 |
text step String Contains step's multi-line text (unicode), otherwise None. |
| 36 |
=============== ========= ============================================= ============================================================== |
| 37 |
|
| 38 |
.. note:: |
| 39 |
|
| 40 |
`Behave attributes`_ in the context object should not be modified by a user. |
| 41 |
See :class:`~behave.runner.Context` class description for more details. |
| 42 |
|
| 43 |
|
| 44 |
User Attributes |
| 45 |
------------------------- |
| 46 |
|
| 47 |
A user can assign (or modify) own attributes to the context object. |
| 48 |
But these attributes will be removed again from the context object depending |
| 49 |
where these attributes are defined. |
| 50 |
|
| 51 |
======= =========================== ======================= |
| 52 |
Kind Assign Location Lifecycle Layer (Scope) |
| 53 |
======= =========================== ======================= |
| 54 |
Hook :func:`before_all` test run |
| 55 |
Hook :func:`after_all` test run |
| 56 |
Hook :func:`before_tags` feature or scenario |
| 57 |
Hook :func:`after_tags` feature or scenario |
| 58 |
Hook :func:`before_feature` feature |
| 59 |
Hook :func:`after_feature` feature |
| 60 |
Hook :func:`before_scenario` scenario |
| 61 |
Hook :func:`after_scenario` scenario |
| 62 |
Hook :func:`before_step` scenario |
| 63 |
Hook :func:`after_step` scenario |
| 64 |
Step Step definition scenario |
| 65 |
======= =========================== ======================= |
| 66 |
|