File: context_attributes.rst

package info (click to toggle)
behave 1.2.6-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,160 kB
  • sloc: python: 19,857; makefile: 137; sh: 18
file content (66 lines) | stat: -rw-r--r-- 3,559 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
.. _id.appendix.context_attributes:

==============================================================================
Context Attributes
==============================================================================

A context object (:class:`~behave.runner.Context`) is handed to

  * step definitions (step implementations)
  * behave hooks (:func:`before_all`, :func:`before_feature`, ..., :func:`after_all`)


Behave Attributes
-------------------------

The :pypi:`behave` runner assigns a number of attributes to the context object
during a test run.

=============== ========= ============================================= ==============================================================
Attribute Name  Layer     Type                                          Description
=============== ========= ============================================= ==============================================================
config          test run  :class:`~behave.configuration.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   :class:`~behave.model.Feature`                Current feature.
tags            feature,  list<:class:`~behave.model.Tag`>              Effective tags of current feature, scenario, scenario outline.
                scenario
active_outline  scenario  :class:`~behave.model.Row`                    Current row in a scenario outline (in examples table).
                outline
scenario        scenario  :class:`~behave.model.Scenario`               Current scenario.
log_capture     scenario  :class:`~behave.log_capture.LoggingCapture`   If logging capture is enabled.
stdout_capture  scenario  :class:`~StringIO.StringIO`                   If stdout  capture is enabled.
stderr_capture  scenario  :class:`~StringIO.StringIO`                   If stderr  capture is enabled.
table           step      :class:`~behave.model.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 :class:`~behave.runner.Context` class description for more details.


User Attributes
-------------------------

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    :func:`before_all`          test run
Hook    :func:`after_all`           test run
Hook    :func:`before_tags`         feature or scenario
Hook    :func:`after_tags`          feature or scenario
Hook    :func:`before_feature`      feature
Hook    :func:`after_feature`       feature
Hook    :func:`before_scenario`     scenario
Hook    :func:`after_scenario`      scenario
Hook    :func:`before_step`         scenario
Hook    :func:`after_step`          scenario
Step    Step definition             scenario
======= =========================== =======================