Skip to content

Commit 5e0e038

Browse files
authored
Merge pull request #2625 from nicoddemus/historical-notes
Historical notes in the docs
2 parents 1a9bc14 + 8c23191 commit 5e0e038

15 files changed

+215
-176
lines changed

doc/en/cache.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ Cache: working with cross-testrun state
55

66
.. versionadded:: 2.8
77

8-
.. warning::
9-
10-
The functionality of this core plugin was previously distributed
11-
as a third party plugin named ``pytest-cache``. The core plugin
12-
is compatible regarding command line options and API usage except that you
13-
can only store/receive data between test runs that is json-serializable.
14-
15-
168
Usage
179
---------
1810

doc/en/contact.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Contact channels
1919
- `pytest-commit at python.org (mailing list)`_: for commits and new issues
2020

2121
- :doc:`contribution guide <contributing>` for help on submitting pull
22-
requests to bitbucket (including using git via gitifyhg).
22+
requests to GitHub.
2323

24-
- #pylib on irc.freenode.net IRC channel for random questions.
24+
- ``#pylib`` on irc.freenode.net IRC channel for random questions.
2525

2626
- private mail to Holger.Krekel at gmail com if you want to communicate sensitive issues
2727

@@ -46,6 +46,5 @@ Contact channels
4646
.. _`py-dev`:
4747
.. _`development mailing list`:
4848
.. _`pytest-dev at python.org (mailing list)`: http://mail.python.org/mailman/listinfo/pytest-dev
49-
.. _`py-svn`:
5049
.. _`pytest-commit at python.org (mailing list)`: http://mail.python.org/mailman/listinfo/pytest-commit
5150

doc/en/contents.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Full pytest documentation
3838
bash-completion
3939

4040
backwards-compatibility
41+
historical-notes
4142
license
4243
contributing
4344
talks

doc/en/example/attic.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ example: specifying and selecting acceptance tests
1717

1818
class AcceptFixture(object):
1919
def __init__(self, request):
20-
if not request.config.option.acceptance:
20+
if not request.config.getoption('acceptance'):
2121
pytest.skip("specify -A to run acceptance tests")
2222
self.tmpdir = request.config.mktemp(request.function.__name__, numbered=True)
2323

doc/en/example/markers.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,18 @@ Or to select "http" and "quick" tests::
173173

174174
.. note::
175175

176-
If you are using expressions such as "X and Y" then both X and Y
177-
need to be simple non-keyword names. For example, "pass" or "from"
178-
will result in SyntaxErrors because "-k" evaluates the expression.
179-
180-
However, if the "-k" argument is a simple string, no such restrictions
181-
apply. Also "-k 'not STRING'" has no restrictions. You can also
182-
specify numbers like "-k 1.3" to match tests which are parametrized
183-
with the float "1.3".
176+
If you are using expressions such as ``"X and Y"`` then both ``X`` and ``Y``
177+
need to be simple non-keyword names. For example, ``"pass"`` or ``"from"``
178+
will result in SyntaxErrors because ``"-k"`` evaluates the expression using
179+
Python's `eval`_ function.
180+
181+
.. _`eval`: https://docs.python.org/3.6/library/functions.html#eval
182+
183+
184+
However, if the ``"-k"`` argument is a simple string, no such restrictions
185+
apply. Also ``"-k 'not STRING'"`` has no restrictions. You can also
186+
specify numbers like ``"-k 1.3"`` to match tests which are parametrized
187+
with the float ``"1.3"``.
184188

185189
Registering markers
186190
-------------------------------------

doc/en/example/parametrize.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Now we add a test configuration like this::
3636

3737
def pytest_generate_tests(metafunc):
3838
if 'param1' in metafunc.fixturenames:
39-
if metafunc.config.option.all:
39+
if metafunc.config.getoption('all'):
4040
end = 5
4141
else:
4242
end = 2

doc/en/fixture.rst

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,14 @@ Note that if you misspell a function argument or want
109109
to use one that isn't available, you'll see an error
110110
with a list of available function arguments.
111111

112-
.. Note::
112+
.. note::
113113

114114
You can always issue::
115115

116116
pytest --fixtures test_simplefactory.py
117117

118118
to see available fixtures.
119119

120-
In versions prior to 2.3 there was no ``@pytest.fixture`` marker
121-
and you had to use a magic ``pytest_funcarg__NAME`` prefix
122-
for the fixture factory. This remains and will remain supported
123-
but is not anymore advertised as the primary means of declaring fixture
124-
functions.
125-
126120
Fixtures: a prime example of dependency injection
127121
---------------------------------------------------
128122

@@ -292,14 +286,6 @@ the ``with`` statement ends.
292286
Note that if an exception happens during the *setup* code (before the ``yield`` keyword), the
293287
*teardown* code (after the ``yield``) will not be called.
294288

295-
296-
.. note::
297-
Prior to version 2.10, in order to use a ``yield`` statement to execute teardown code one
298-
had to mark a fixture using the ``yield_fixture`` marker. From 2.10 onward, normal
299-
fixtures can use ``yield`` directly so the ``yield_fixture`` decorator is no longer needed
300-
and considered deprecated.
301-
302-
303289
An alternative option for executing *teardown* code is to
304290
make use of the ``addfinalizer`` method of the `request-context`_ object to register
305291
finalization functions.

doc/en/goodpractices.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,6 @@ by putting them into a ``[tool:pytest]`` section:
249249
python_files = testing/*/*.py
250250
251251
252-
.. note::
253-
Prior to 3.0, the supported section name was ``[pytest]``. Due to how
254-
this may collide with some distutils commands, the recommended
255-
section name for ``setup.cfg`` files is now ``[tool:pytest]``.
256-
257-
Note that for ``pytest.ini`` and ``tox.ini`` files the section
258-
name is ``[pytest]``.
259-
260-
261252
Manual Integration
262253
^^^^^^^^^^^^^^^^^^
263254

doc/en/historical-notes.rst

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
Historical Notes
2+
================
3+
4+
This page lists features or behavior from previous versions of pytest which have changed over the years. They are
5+
kept here as a historical note so users looking at old code can find documentation related to them.
6+
7+
cache plugin integrated into the core
8+
-------------------------------------
9+
10+
.. versionadded:: 2.8
11+
12+
The functionality of the :ref:`core cache <cache>` plugin was previously distributed
13+
as a third party plugin named ``pytest-cache``. The core plugin
14+
is compatible regarding command line options and API usage except that you
15+
can only store/receive data between test runs that is json-serializable.
16+
17+
18+
funcargs and ``pytest_funcarg__``
19+
---------------------------------
20+
21+
.. versionchanged:: 2.3
22+
23+
In versions prior to 2.3 there was no ``@pytest.fixture`` marker
24+
and you had to use a magic ``pytest_funcarg__NAME`` prefix
25+
for the fixture factory. This remains and will remain supported
26+
but is not anymore advertised as the primary means of declaring fixture
27+
functions.
28+
29+
30+
``@pytest.yield_fixture`` decorator
31+
-----------------------------------
32+
33+
.. versionchanged:: 2.10
34+
35+
Prior to version 2.10, in order to use a ``yield`` statement to execute teardown code one
36+
had to mark a fixture using the ``yield_fixture`` marker. From 2.10 onward, normal
37+
fixtures can use ``yield`` directly so the ``yield_fixture`` decorator is no longer needed
38+
and considered deprecated.
39+
40+
41+
``[pytest]`` header in ``setup.cfg``
42+
------------------------------------
43+
44+
.. versionchanged:: 3.0
45+
46+
Prior to 3.0, the supported section name was ``[pytest]``. Due to how
47+
this may collide with some distutils commands, the recommended
48+
section name for ``setup.cfg`` files is now ``[tool:pytest]``.
49+
50+
Note that for ``pytest.ini`` and ``tox.ini`` files the section
51+
name is ``[pytest]``.
52+
53+
54+
Applying marks to ``@pytest.mark.parametrize`` parameters
55+
---------------------------------------------------------
56+
57+
.. versionchanged:: 3.1
58+
59+
Prior to version 3.1 the supported mechanism for marking values
60+
used the syntax::
61+
62+
import pytest
63+
@pytest.mark.parametrize("test_input,expected", [
64+
("3+5", 8),
65+
("2+4", 6),
66+
pytest.mark.xfail(("6*9", 42),),
67+
])
68+
def test_eval(test_input, expected):
69+
assert eval(test_input) == expected
70+
71+
72+
This was an initial hack to support the feature but soon was demonstrated to be incomplete,
73+
broken for passing functions or applying multiple marks with the same name but different parameters.
74+
75+
The old syntax is planned to be removed in pytest-4.0.
76+
77+
78+
``@pytest.mark.parametrize`` argument names as a tuple
79+
------------------------------------------------------
80+
81+
.. versionchanged:: 2.4
82+
83+
In versions prior to 2.4 one needed to specify the argument
84+
names as a tuple. This remains valid but the simpler ``"name1,name2,..."``
85+
comma-separated-string syntax is now advertised first because
86+
it's easier to write and produces less line noise.
87+
88+
89+
setup: is now an "autouse fixture"
90+
----------------------------------
91+
92+
.. versionchanged:: 2.3
93+
94+
During development prior to the pytest-2.3 release the name
95+
``pytest.setup`` was used but before the release it was renamed
96+
and moved to become part of the general fixture mechanism,
97+
namely :ref:`autouse fixtures`
98+
99+
100+
.. _string conditions:
101+
102+
Conditions as strings instead of booleans
103+
-----------------------------------------
104+
105+
.. versionchanged:: 2.4
106+
107+
Prior to pytest-2.4 the only way to specify skipif/xfail conditions was
108+
to use strings::
109+
110+
import sys
111+
@pytest.mark.skipif("sys.version_info >= (3,3)")
112+
def test_function():
113+
...
114+
115+
During test function setup the skipif condition is evaluated by calling
116+
``eval('sys.version_info >= (3,0)', namespace)``. The namespace contains
117+
all the module globals, and ``os`` and ``sys`` as a minimum.
118+
119+
Since pytest-2.4 :ref:`boolean conditions <condition booleans>` are considered preferable
120+
because markers can then be freely imported between test modules.
121+
With strings you need to import not only the marker but all variables
122+
used by the marker, which violates encapsulation.
123+
124+
The reason for specifying the condition as a string was that ``pytest`` can
125+
report a summary of skip conditions based purely on the condition string.
126+
With conditions as booleans you are required to specify a ``reason`` string.
127+
128+
Note that string conditions will remain fully supported and you are free
129+
to use them if you have no need for cross-importing markers.
130+
131+
The evaluation of a condition string in ``pytest.mark.skipif(conditionstring)``
132+
or ``pytest.mark.xfail(conditionstring)`` takes place in a namespace
133+
dictionary which is constructed as follows:
134+
135+
* the namespace is initialized by putting the ``sys`` and ``os`` modules
136+
and the pytest ``config`` object into it.
137+
138+
* updated with the module globals of the test function for which the
139+
expression is applied.
140+
141+
The pytest ``config`` object allows you to skip based on a test
142+
configuration value which you might have added::
143+
144+
@pytest.mark.skipif("not config.getvalue('db')")
145+
def test_function(...):
146+
...
147+
148+
The equivalent with "boolean conditions" is::
149+
150+
@pytest.mark.skipif(not pytest.config.getvalue("db"),
151+
reason="--db was not specified")
152+
def test_function(...):
153+
pass
154+
155+
.. note::
156+
157+
You cannot use ``pytest.config.getvalue()`` in code
158+
imported before pytest's argument parsing takes place. For example,
159+
``conftest.py`` files are imported before command line parsing and thus
160+
``config.getvalue()`` will not execute correctly.
161+
162+
``pytest.set_trace()``
163+
----------------------
164+
165+
.. versionchanged:: 2.4
166+
167+
Previous to version 2.4 to set a break point in code one needed to use ``pytest.set_trace()``::
168+
169+
import pytest
170+
def test_function():
171+
...
172+
pytest.set_trace() # invoke PDB debugger and tracing
173+
174+
175+
This is no longer needed and one can use the native ``import pdb;pdb.set_trace()`` call directly.
176+
177+
For more details see :ref:`breakpoints`.

doc/en/parametrize.rst

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,6 @@ for example with the builtin ``mark.xfail``::
9999
def test_eval(test_input, expected):
100100
assert eval(test_input) == expected
101101

102-
.. note::
103-
104-
prior to version 3.1 the supported mechanism for marking values
105-
used the syntax::
106-
107-
import pytest
108-
@pytest.mark.parametrize("test_input,expected", [
109-
("3+5", 8),
110-
("2+4", 6),
111-
pytest.mark.xfail(("6*9", 42),),
112-
])
113-
def test_eval(test_input, expected):
114-
assert eval(test_input) == expected
115-
116-
117-
This was an initial hack to support the feature but soon was demonstrated to be incomplete,
118-
broken for passing functions or applying multiple marks with the same name but different parameters.
119-
The old syntax will be removed in pytest-4.0.
120-
121-
122102
Let's run this::
123103

124104
$ pytest
@@ -143,15 +123,8 @@ To get all combinations of multiple parametrized arguments you can stack
143123
def test_foo(x, y):
144124
pass
145125

146-
This will run the test with the arguments set to x=0/y=2, x=0/y=3, x=1/y=2 and
147-
x=1/y=3.
148-
149-
.. note::
150-
151-
In versions prior to 2.4 one needed to specify the argument
152-
names as a tuple. This remains valid but the simpler ``"name1,name2,..."``
153-
comma-separated-string syntax is now advertised first because
154-
it's easier to write and produces less line noise.
126+
This will run the test with the arguments set to ``x=0/y=2``, ``x=0/y=3``, ``x=1/y=2`` and
127+
``x=1/y=3``.
155128

156129
.. _`pytest_generate_tests`:
157130

@@ -187,7 +160,7 @@ command line option and the parametrization of our test function::
187160
def pytest_generate_tests(metafunc):
188161
if 'stringinput' in metafunc.fixturenames:
189162
metafunc.parametrize("stringinput",
190-
metafunc.config.option.stringinput)
163+
metafunc.config.getoption('stringinput'))
191164

192165
If we now pass two stringinput values, our test will run twice::
193166

doc/en/setup.rst

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)