Debian Codegraph @

docs/formatters.rst

raw
1 .. _id.appendix.formatters:
2
3 ==============================================================================
4 Formatters and Reporters
5 ==============================================================================
6
7 :pypi:`behave` provides 2 different concepts for reporting results of a test run:
8
9 * formatters
10 * reporters
11
12 A slightly different interface is provided for each "formatter" concept.
13 The ``Formatter`` is informed about each step that is taken.
14 The ``Reporter`` has a more coarse-grained API.
15
16
17 Reporters
18 ------------------------------------------------------------------------------
19
20 The following reporters are currently supported:
21
22 ============== ================================================================
23 Name Description
24 ============== ================================================================
25 junit Provides JUnit XML-like output.
26 summary Provides a summary of the test run.
27 ============== ================================================================
28
29
30 Formatters
31 ------------------------------------------------------------------------------
32
33 The following formatters are currently supported:
34
35 ============== ======== ================================================================
36 Name Mode Description
37 ============== ======== ================================================================
38 help normal Shows all registered formatters.
39 json normal JSON dump of test run
40 json.pretty normal JSON dump of test run (human readable)
41 plain normal Very basic formatter with maximum compatibility
42 pretty normal Standard colourised pretty formatter
43 progress normal Shows dotted progress for each executed scenario.
44 progress2 normal Shows dotted progress for each executed step.
45 progress3 normal Shows detailed progress for each step of a scenario.
46 rerun normal Emits scenario file locations of failing scenarios
47 sphinx.steps dry-run Generate sphinx-based documentation for step definitions.
48 steps dry-run Shows step definitions (step implementations).
49 steps.doc dry-run Shows documentation for step definitions.
50 steps.usage dry-run Shows how step definitions are used by steps (in feature files).
51 tags dry-run Shows tags (and how often they are used).
52 tags.location dry-run Shows tags and the location where they are used.
53 ============== ======== ================================================================
54
55 .. note::
56
57 You can use more than one formatter during a test run.
58 But in general you have only one formatter that writes to ``stdout``.
59
60 The "Mode" column indicates if a formatter is intended to be used in
61 dry-run (``--dry-run`` command-line option) or normal mode.
62
63
64 User-Defined Formatters
65 ------------------------------------------------------------------------------
66
67 Behave allows you to provide your own formatter (class)::
68
69 # -- USE: Formatter class "Json2Formatter" in python module "foo.bar"
70 # NOTE: Formatter must be importable from python search path.
71 behave -f foo.bar:Json2Formatter ...
72
73 The usage of a user-defined formatter can be simplified by providing an
74 alias name for it in the configuration file:
75
76 .. code-block:: ini
77
78 # -- FILE: behave.ini
79 # ALIAS SUPPORTS: behave -f json2 ...
80 # NOTE: Formatter aliases may override builtin formatters.
81 [behave.formatters]
82 json2 = foo.bar:Json2Formatter
83
84 If your formatter can be configured, you should use the userdata concept
85 to provide them. The formatter should use the attribute schema:
86
87 .. code-block:: ini
88
89 # -- FILE: behave.ini
90 # SCHEMA: behave.formatter.<FORMATTER_NAME>.<ATTRIBUTE_NAME>
91 [behave.userdata]
92 behave.formatter.json2.use_pretty = true
93
94 # -- SUPPORTS ALSO:
95 # behave -f json2 -D behave.formatter.json2.use_pretty ...
96
97
98 More Formatters
99 ------------------------------------------------------------------------------
100
101 The following formatters are currently known:
102
103 ============== =========================================================================
104 Name Description
105 ============== =========================================================================
106 allure :pypi:`allure-behave`, an Allure formatter for behave:
107 ``allure_behave.formatter:AllureFormatter``
108 teamcity :pypi:`behave-teamcity`, a formatter for Jetbrains TeamCity CI testruns
109 with behave.
110 ============== =========================================================================
111
112 .. code-block:: ini
113
114 # -- FILE: behave.ini
115 # FORMATTER ALIASES: behave -f allure ...
116 [behave.formatters]
117 allure = allure_behave.formatter:AllureFormatter
118 teamcity = behave_teamcity:TeamcityFormatter