A context object (Context) is handed to
- step definitions (step implementations)
- behave hooks (before_all(), before_feature(), ..., after_all())
The behave runner assigns a number of attributes to the context object during a test run.
Attribute Name | Layer | Type | Description |
---|---|---|---|
config | test run | Configuration | Configuration that is used. |
aborted | test run | bool | Set to true if test run is aborted by the user. |
failed | test run | bool | Set to true if a step fails. |
feature | feature | Feature | Current feature. |
tags | feature, scenario | list<Tag> | Effective tags of current feature, scenario, scenario outline. |
active_outline | scenario outline | Row | Current row in a scenario outline (in examples table). |
scenario | scenario | Scenario | Current scenario. |
log_capture | scenario | LoggingCapture | If logging capture is enabled. |
stdout_capture | scenario | StringIO | If stdout capture is enabled. |
stderr_capture | scenario | StringIO | If stderr capture is enabled. |
table | step | Table | Contains step’s table, otherwise None. |
text | step | String | Contains step’s multi-line text (unicode), otherwise None. |
Note
Behave attributes in the context object should not be modified by a user. See Context class description for more details.
A user can assign (or modify) own attributes to the context object. But these attributes will be removed again from the context object depending where these attributes are defined.
Kind | Assign Location | Lifecycle Layer (Scope) |
---|---|---|
Hook | before_all() | test run |
Hook | after_all() | test run |
Hook | before_tags() | feature or scenario |
Hook | after_tags() | feature or scenario |
Hook | before_feature() | feature |
Hook | after_feature() | feature |
Hook | before_scenario() | scenario |
Hook | after_scenario() | scenario |
Hook | before_step() | scenario |
Hook | after_step() | scenario |
Step | Step definition | scenario |