Debian Codegraph @

doc/en/announce/release-2.4.0.rst

raw
1 pytest-2.4.0: new fixture features/hooks and bug fixes
2 ===========================================================================
3
4 The just released pytest-2.4.0 brings many improvements and numerous
5 bug fixes while remaining plugin- and test-suite compatible apart
6 from a few supposedly very minor incompatibilities. See below for
7 a full list of details. A few feature highlights:
8
9 - new yield-style fixtures `pytest.yield_fixture
10 <http://pytest.org/en/stable/yieldfixture.html>`_, allowing to use
11 existing with-style context managers in fixture functions.
12
13 - improved pdb support: ``import pdb ; pdb.set_trace()`` now works
14 without requiring prior disabling of stdout/stderr capturing.
15 Also the ``--pdb`` options works now on collection and internal errors
16 and we introduced a new experimental hook for IDEs/plugins to
17 intercept debugging: ``pytest_exception_interact(node, call, report)``.
18
19 - shorter monkeypatch variant to allow specifying an import path as
20 a target, for example: ``monkeypatch.setattr("requests.get", myfunc)``
21
22 - better unittest/nose compatibility: all teardown methods are now only
23 called if the corresponding setup method succeeded.
24
25 - integrate tab-completion on command line options if you
26 have :pypi:`argcomplete` configured.
27
28 - allow boolean expression directly with skipif/xfail
29 if a "reason" is also specified.
30
31 - a new hook ``pytest_load_initial_conftests`` allows plugins like
32 :pypi:`pytest-django` to
33 influence the environment before conftest files import ``django``.
34
35 - reporting: color the last line red or green depending if
36 failures/errors occurred or everything passed.
37
38 The documentation has been updated to accommodate the changes,
39 see `http://pytest.org <http://pytest.org>`_
40
41 To install or upgrade pytest::
42
43 pip install -U pytest # or
44 easy_install -U pytest
45
46
47 **Many thanks to all who helped, including Floris Bruynooghe,
48 Brianna Laugher, Andreas Pelme, Anthon van der Neut, Anatoly Bubenkoff,
49 Vladimir Keleshev, Mathieu Agopian, Ronny Pfannschmidt, Christian
50 Theunert and many others.**
51
52 may passing tests be with you,
53
54 holger krekel
55
56 Changes between 2.3.5 and 2.4
57 -----------------------------------
58
59 known incompatibilities:
60
61 - if calling --genscript from python2.7 or above, you only get a
62 standalone script which works on python2.7 or above. Use Python2.6
63 to also get a python2.5 compatible version.
64
65 - all xunit-style teardown methods (nose-style, pytest-style,
66 unittest-style) will not be called if the corresponding setup method failed,
67 see issue322 below.
68
69 - the pytest_plugin_unregister hook wasn't ever properly called
70 and there is no known implementation of the hook - so it got removed.
71
72 - pytest.fixture-decorated functions cannot be generators (i.e. use
73 yield) anymore. This change might be reversed in 2.4.1 if it causes
74 unforeseen real-life issues. However, you can always write and return
75 an inner function/generator and change the fixture consumer to iterate
76 over the returned generator. This change was done in lieu of the new
77 ``pytest.yield_fixture`` decorator, see below.
78
79 new features:
80
81 - experimentally introduce a new ``pytest.yield_fixture`` decorator
82 which accepts exactly the same parameters as pytest.fixture but
83 mandates a ``yield`` statement instead of a ``return statement`` from
84 fixture functions. This allows direct integration with "with-style"
85 context managers in fixture functions and generally avoids registering
86 of finalization callbacks in favour of treating the "after-yield" as
87 teardown code. Thanks Andreas Pelme, Vladimir Keleshev, Floris
88 Bruynooghe, Ronny Pfannschmidt and many others for discussions.
89
90 - allow boolean expression directly with skipif/xfail
91 if a "reason" is also specified. Rework skipping documentation
92 to recommend "condition as booleans" because it prevents surprises
93 when importing markers between modules. Specifying conditions
94 as strings will remain fully supported.
95
96 - reporting: color the last line red or green depending if
97 failures/errors occurred or everything passed. thanks Christian
98 Theunert.
99
100 - make "import pdb ; pdb.set_trace()" work natively wrt capturing (no
101 "-s" needed anymore), making ``pytest.set_trace()`` a mere shortcut.
102
103 - fix issue181: --pdb now also works on collect errors (and
104 on internal errors) . This was implemented by a slight internal
105 refactoring and the introduction of a new hook
106 ``pytest_exception_interact`` hook (see next item).
107
108 - fix issue341: introduce new experimental hook for IDEs/terminals to
109 intercept debugging: ``pytest_exception_interact(node, call, report)``.
110
111 - new monkeypatch.setattr() variant to provide a shorter
112 invocation for patching out classes/functions from modules:
113
114 monkeypatch.setattr("requests.get", myfunc)
115
116 will replace the "get" function of the "requests" module with ``myfunc``.
117
118 - fix issue322: tearDownClass is not run if setUpClass failed. Thanks
119 Mathieu Agopian for the initial fix. Also make all of pytest/nose
120 finalizer mimic the same generic behaviour: if a setupX exists and
121 fails, don't run teardownX. This internally introduces a new method
122 "node.addfinalizer()" helper which can only be called during the setup
123 phase of a node.
124
125 - simplify pytest.mark.parametrize() signature: allow to pass a
126 CSV-separated string to specify argnames. For example:
127 ``pytest.mark.parametrize("input,expected", [(1,2), (2,3)])``
128 works as well as the previous:
129 ``pytest.mark.parametrize(("input", "expected"), ...)``.
130
131 - add support for setUpModule/tearDownModule detection, thanks Brian Okken.
132
133 - integrate tab-completion on options through use of "argcomplete".
134 Thanks Anthon van der Neut for the PR.
135
136 - change option names to be hyphen-separated long options but keep the
137 old spelling backward compatible. py.test -h will only show the
138 hyphenated version, for example "--collect-only" but "--collectonly"
139 will remain valid as well (for backward-compat reasons). Many thanks to
140 Anthon van der Neut for the implementation and to Hynek Schlawack for
141 pushing us.
142
143 - fix issue 308 - allow to mark/xfail/skip individual parameter sets
144 when parametrizing. Thanks Brianna Laugher.
145
146 - call new experimental pytest_load_initial_conftests hook to allow
147 3rd party plugins to do something before a conftest is loaded.
148
149 Bug fixes:
150
151 - fix issue358 - capturing options are now parsed more properly
152 by using a new parser.parse_known_args method.
153
154 - pytest now uses argparse instead of optparse (thanks Anthon) which
155 means that "argparse" is added as a dependency if installing into python2.6
156 environments or below.
157
158 - fix issue333: fix a case of bad unittest/pytest hook interaction.
159
160 - PR27: correctly handle nose.SkipTest during collection. Thanks
161 Antonio Cuni, Ronny Pfannschmidt.
162
163 - fix issue355: junitxml puts name="pytest" attribute to testsuite tag.
164
165 - fix issue336: autouse fixture in plugins should work again.
166
167 - fix issue279: improve object comparisons on assertion failure
168 for standard datatypes and recognise collections.abc. Thanks to
169 Brianna Laugher and Mathieu Agopian.
170
171 - fix issue317: assertion rewriter support for the is_package method
172
173 - fix issue335: document py.code.ExceptionInfo() object returned
174 from pytest.raises(), thanks Mathieu Agopian.
175
176 - remove implicit distribute_setup support from setup.py.
177
178 - fix issue305: ignore any problems when writing pyc files.
179
180 - SO-17664702: call fixture finalizers even if the fixture function
181 partially failed (finalizers would not always be called before)
182
183 - fix issue320 - fix class scope for fixtures when mixed with
184 module-level functions. Thanks Anatoly Bubenkoff.
185
186 - you can specify "-q" or "-qq" to get different levels of "quieter"
187 reporting (thanks Katarzyna Jachim)
188
189 - fix issue300 - Fix order of conftest loading when starting py.test
190 in a subdirectory.
191
192 - fix issue323 - sorting of many module-scoped arg parametrizations
193
194 - make sessionfinish hooks execute with the same cwd-context as at
195 session start (helps fix plugin behaviour which write output files
196 with relative path such as pytest-cov)
197
198 - fix issue316 - properly reference collection hooks in docs
199
200 - fix issue 306 - cleanup of -k/-m options to only match markers/test
201 names/keywords respectively. Thanks Wouter van Ackooy.
202
203 - improved doctest counting for doctests in python modules --
204 files without any doctest items will not show up anymore
205 and doctest examples are counted as separate test items.
206 thanks Danilo Bellini.
207
208 - fix issue245 by depending on the released py-1.4.14
209 which fixes py.io.dupfile to work with files with no
210 mode. Thanks Jason R. Coombs.
211
212 - fix junitxml generation when test output contains control characters,
213 addressing issue267, thanks Jaap Broekhuizen
214
215 - fix issue338: honor --tb style for setup/teardown errors as well. Thanks Maho.
216
217 - fix issue307 - use yaml.safe_load in example, thanks Mark Eichin.
218
219 - better parametrize error messages, thanks Brianna Laugher
220
221 - pytest_terminal_summary(terminalreporter) hooks can now use
222 ".section(title)" and ".line(msg)" methods to print extra
223 information at the end of a test run.