Skip to content

Commit 1ca4938

Browse files
emmett-rayescsernazs
authored andcommitted
pytest_plugin.py: add deprecation warnings for httpserver_listen_address
Also add upgrade guide for version 1.0.0.
1 parent a37e7e4 commit 1ca4938

4 files changed

Lines changed: 89 additions & 1 deletion

File tree

doc/changes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
.. _changes:
2+
13
.. release-notes:: Release Notes
24

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ For further details, please read the :doc:`guide` or the :doc:`api`.
4141
api
4242
background
4343
changes
44+
upgrade

doc/upgrade.rst

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
.. _upgrade:
2+
3+
Upgrade guides
4+
==============
5+
6+
The following document describes how to upgrade to a given version of the
7+
library which introduces breaking changes.
8+
9+
Introducing breaking changes
10+
----------------------------
11+
When a breaking change is about to be made in the library, an intermediate
12+
release is released which generates deprecation warnings when the functionality
13+
to be removed is used. This does not break any functionality but shows a
14+
warning instead.
15+
16+
Together with this intermediate release, a new *pre-release* is released to
17+
*pypi*. This release removes the functionality described by the warning, but
18+
*pip* does not install this version unless you specify the *--pre* parameter to
19+
*pip install*.
20+
21+
Once you made the required changes to make your code compatible with the new
22+
version, you can install the new version by *pip install --pre
23+
pytest-httpserver*.
24+
25+
After a given time period, a new non-pre release is released, this will be
26+
installed by pip similar to other releases and it will break your code if you
27+
have not made the required changes. If this happens, you can still pin the
28+
version in requirements.txt or other places. Usually specifying the version with
29+
`==` operator fixes the version, but for more details please read the
30+
documentation of the tool you are using in manage dependencies.
31+
32+
33+
1.0.0
34+
-----
35+
36+
In pytest-httpserver 1.0.0 the following breaking changes were made.
37+
38+
* The scope of ``httpserver_listen_address`` fixture changed from **function** to **session**
39+
40+
In order to make your code compatible with the new version of pytest-httpserver,
41+
you need to specify the `session` scope explicitly.
42+
43+
Example
44+
~~~~~~~
45+
46+
Old code:
47+
48+
.. code-block:: python
49+
50+
import pytest
51+
52+
@pytest.fixture
53+
def httpserver_listen_address():
54+
return ("127.0.0.1", 8888)
55+
56+
New code:
57+
58+
.. code-block:: python
59+
60+
import pytest
61+
62+
@pytest.fixture(scope="session")
63+
def httpserver_listen_address():
64+
return ("127.0.0.1", 8888)
65+
66+
67+
As this fixture is now defined with session scope, it will be called only once,
68+
when it is first referenced by a test or by another fixture.
69+
70+
.. note::
71+
72+
There were other, non-breaking changes introduced to 1.0.0. For details,
73+
please read the :ref:`changes`.

pytest_httpserver/pytest_plugin.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

2-
32
import os
3+
import warnings
44

55
import pytest
6+
67
from .httpserver import HTTPServer
78

89

@@ -57,3 +58,14 @@ def pytest_sessionfinish(session, exitstatus): # pylint: disable=unused-argumen
5758
Plugin.SERVER.clear()
5859
if Plugin.SERVER.is_running():
5960
Plugin.SERVER.stop()
61+
62+
63+
@pytest.hookimpl(hookwrapper=True)
64+
def pytest_fixture_setup(fixturedef, request): # pylint: disable=unused-argument
65+
if fixturedef.argname == 'httpserver_listen_address' and fixturedef.scope != 'session':
66+
warnings.warn("httpserver_listen_address fixture will be converted to session scope in version 1.0.0. "
67+
"Details: https://pytest-httpserver.readthedocs.io/en/latest/upgrade.html",
68+
DeprecationWarning)
69+
yield
70+
else:
71+
yield

0 commit comments

Comments
 (0)