Skip to content

Commit 368cc62

Browse files
[8.0.x] Upgrade blacken-doc to black's 2024 style (#11899) (#11900)
(cherry picked from commit 4546d54) Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent 06e5923 commit 368cc62

File tree

7 files changed

+42
-83
lines changed

7 files changed

+42
-83
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repos:
88
rev: 1.16.0
99
hooks:
1010
- id: blacken-docs
11-
additional_dependencies: [black==23.7.0]
11+
additional_dependencies: [black==24.1.1]
1212
- repo: https://github.com/pre-commit/pre-commit-hooks
1313
rev: v4.5.0
1414
hooks:

doc/en/deprecations.rst

+21-42
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ they are in fact part of the ``nose`` support.
4747
def teardown(self):
4848
self.resource.close()
4949
50-
def test_foo(self):
51-
...
50+
def test_foo(self): ...
5251
53-
def test_bar(self):
54-
...
52+
def test_bar(self): ...
5553
5654
5755
@@ -66,11 +64,9 @@ Native pytest support uses ``setup_method`` and ``teardown_method`` (see :ref:`x
6664
def teardown_method(self):
6765
self.resource.close()
6866
69-
def test_foo(self):
70-
...
67+
def test_foo(self): ...
7168
72-
def test_bar(self):
73-
...
69+
def test_bar(self): ...
7470
7571
7672
This is easy to do in an entire code base by doing a simple find/replace.
@@ -85,17 +81,14 @@ Code using `@with_setup <with-setup-nose>`_ such as this:
8581
from nose.tools import with_setup
8682
8783
88-
def setup_some_resource():
89-
...
84+
def setup_some_resource(): ...
9085
9186
92-
def teardown_some_resource():
93-
...
87+
def teardown_some_resource(): ...
9488
9589
9690
@with_setup(setup_some_resource, teardown_some_resource)
97-
def test_foo():
98-
...
91+
def test_foo(): ...
9992
10093
Will also need to be ported to a supported pytest style. One way to do it is using a fixture:
10194

@@ -104,12 +97,10 @@ Will also need to be ported to a supported pytest style. One way to do it is usi
10497
import pytest
10598
10699
107-
def setup_some_resource():
108-
...
100+
def setup_some_resource(): ...
109101
110102
111-
def teardown_some_resource():
112-
...
103+
def teardown_some_resource(): ...
113104
114105
115106
@pytest.fixture
@@ -119,8 +110,7 @@ Will also need to be ported to a supported pytest style. One way to do it is usi
119110
teardown_some_resource()
120111
121112
122-
def test_foo(some_resource):
123-
...
113+
def test_foo(some_resource): ...
124114
125115
126116
.. _`with-setup-nose`: https://nose.readthedocs.io/en/latest/testing_tools.html?highlight=with_setup#nose.tools.with_setup
@@ -197,13 +187,11 @@ have been available since years and should be used instead.
197187
.. code-block:: python
198188
199189
@pytest.mark.tryfirst
200-
def pytest_runtest_call():
201-
...
190+
def pytest_runtest_call(): ...
202191
203192
204193
# or
205-
def pytest_runtest_call():
206-
...
194+
def pytest_runtest_call(): ...
207195
208196
209197
pytest_runtest_call.tryfirst = True
@@ -213,8 +201,7 @@ should be changed to:
213201
.. code-block:: python
214202
215203
@pytest.hookimpl(tryfirst=True)
216-
def pytest_runtest_call():
217-
...
204+
def pytest_runtest_call(): ...
218205
219206
Changed ``hookimpl`` attributes:
220207

@@ -317,17 +304,15 @@ Implement the :hook:`pytest_load_initial_conftests` hook instead.
317304

318305
.. code-block:: python
319306
320-
def pytest_cmdline_preparse(config: Config, args: List[str]) -> None:
321-
...
307+
def pytest_cmdline_preparse(config: Config, args: List[str]) -> None: ...
322308
323309
324310
# becomes:
325311
326312
327313
def pytest_load_initial_conftests(
328314
early_config: Config, parser: Parser, args: List[str]
329-
) -> None:
330-
...
315+
) -> None: ...
331316
332317
.. _diamond-inheritance-deprecated:
333318

@@ -391,8 +376,7 @@ Applying a mark to a fixture function never had any effect, but it is a common u
391376
392377
@pytest.mark.usefixtures("clean_database")
393378
@pytest.fixture
394-
def user() -> User:
395-
...
379+
def user() -> User: ...
396380
397381
Users expected in this case that the ``usefixtures`` mark would have its intended effect of using the ``clean_database`` fixture when ``user`` was invoked, when in fact it has no effect at all.
398382

@@ -907,8 +891,7 @@ Applying marks to values of a ``pytest.mark.parametrize`` call is now deprecated
907891
(50, 500),
908892
],
909893
)
910-
def test_foo(a, b):
911-
...
894+
def test_foo(a, b): ...
912895
913896
This code applies the ``pytest.mark.xfail(reason="flaky")`` mark to the ``(6, 36)`` value of the above parametrization
914897
call.
@@ -931,8 +914,7 @@ To update the code, use ``pytest.param``:
931914
(50, 500),
932915
],
933916
)
934-
def test_foo(a, b):
935-
...
917+
def test_foo(a, b): ...
936918
937919
938920
.. _pytest_funcarg__ prefix deprecated:
@@ -1083,15 +1065,13 @@ This is just a matter of renaming the fixture as the API is the same:
10831065

10841066
.. code-block:: python
10851067
1086-
def test_foo(record_xml_property):
1087-
...
1068+
def test_foo(record_xml_property): ...
10881069
10891070
Change to:
10901071

10911072
.. code-block:: python
10921073
1093-
def test_foo(record_property):
1094-
...
1074+
def test_foo(record_property): ...
10951075
10961076
10971077
.. _passing command-line string to pytest.main deprecated:
@@ -1253,8 +1233,7 @@ Example of usage:
12531233

12541234
.. code-block:: python
12551235
1256-
class MySymbol:
1257-
...
1236+
class MySymbol: ...
12581237
12591238
12601239
def pytest_namespace():

doc/en/funcarg_compare.rst

+3-6
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ sets. pytest-2.3 introduces a decorator for use on the factory itself:
9999
.. code-block:: python
100100
101101
@pytest.fixture(params=["mysql", "pg"])
102-
def db(request):
103-
... # use request.param
102+
def db(request): ... # use request.param
104103
105104
Here the factory will be invoked twice (with the respective "mysql"
106105
and "pg" values set as ``request.param`` attributes) and all of
@@ -141,8 +140,7 @@ argument:
141140
.. code-block:: python
142141
143142
@pytest.fixture()
144-
def db(request):
145-
...
143+
def db(request): ...
146144
147145
The name under which the funcarg resource can be requested is ``db``.
148146

@@ -151,8 +149,7 @@ aka:
151149

152150
.. code-block:: python
153151
154-
def pytest_funcarg__db(request):
155-
...
152+
def pytest_funcarg__db(request): ...
156153
157154
158155
But it is then not possible to define scoping and parametrization.

doc/en/historical-notes.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ to use strings:
227227
228228
229229
@pytest.mark.skipif("sys.version_info >= (3,3)")
230-
def test_function():
231-
...
230+
def test_function(): ...
232231
233232
During test function setup the skipif condition is evaluated by calling
234233
``eval('sys.version_info >= (3,0)', namespace)``. The namespace contains
@@ -262,8 +261,7 @@ configuration value which you might have added:
262261
.. code-block:: python
263262
264263
@pytest.mark.skipif("not config.getvalue('db')")
265-
def test_function():
266-
...
264+
def test_function(): ...
267265
268266
The equivalent with "boolean conditions" is:
269267

doc/en/how-to/fixtures.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -1721,8 +1721,7 @@ You can specify multiple fixtures like this:
17211721
.. code-block:: python
17221722
17231723
@pytest.mark.usefixtures("cleandir", "anotherfixture")
1724-
def test():
1725-
...
1724+
def test(): ...
17261725
17271726
and you may specify fixture usage at the test module level using :globalvar:`pytestmark`:
17281727

@@ -1750,8 +1749,7 @@ into an ini-file:
17501749
17511750
@pytest.mark.usefixtures("my_other_fixture")
17521751
@pytest.fixture
1753-
def my_fixture_that_sadly_wont_use_my_other_fixture():
1754-
...
1752+
def my_fixture_that_sadly_wont_use_my_other_fixture(): ...
17551753
17561754
This generates a deprecation warning, and will become an error in Pytest 8.
17571755

doc/en/how-to/skipping.rst

+10-20
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ which may be passed an optional ``reason``:
4747
.. code-block:: python
4848
4949
@pytest.mark.skip(reason="no way of currently testing this")
50-
def test_the_unknown():
51-
...
50+
def test_the_unknown(): ...
5251
5352
5453
Alternatively, it is also possible to skip imperatively during test execution or setup
@@ -93,8 +92,7 @@ when run on an interpreter earlier than Python3.10:
9392
9493
9594
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher")
96-
def test_function():
97-
...
95+
def test_function(): ...
9896
9997
If the condition evaluates to ``True`` during collection, the test function will be skipped,
10098
with the specified reason appearing in the summary when using ``-rs``.
@@ -112,8 +110,7 @@ You can share ``skipif`` markers between modules. Consider this test module:
112110
113111
114112
@minversion
115-
def test_function():
116-
...
113+
def test_function(): ...
117114
118115
You can import the marker and reuse it in another test module:
119116

@@ -124,8 +121,7 @@ You can import the marker and reuse it in another test module:
124121
125122
126123
@minversion
127-
def test_anotherfunction():
128-
...
124+
def test_anotherfunction(): ...
129125
130126
For larger test suites it's usually a good idea to have one file
131127
where you define the markers which you then consistently apply
@@ -232,8 +228,7 @@ expect a test to fail:
232228
.. code-block:: python
233229
234230
@pytest.mark.xfail
235-
def test_function():
236-
...
231+
def test_function(): ...
237232
238233
This test will run but no traceback will be reported when it fails. Instead, terminal
239234
reporting will list it in the "expected to fail" (``XFAIL``) or "unexpectedly
@@ -275,8 +270,7 @@ that condition as the first parameter:
275270
.. code-block:: python
276271
277272
@pytest.mark.xfail(sys.platform == "win32", reason="bug in a 3rd party library")
278-
def test_function():
279-
...
273+
def test_function(): ...
280274
281275
Note that you have to pass a reason as well (see the parameter description at
282276
:ref:`pytest.mark.xfail ref`).
@@ -289,8 +283,7 @@ You can specify the motive of an expected failure with the ``reason`` parameter:
289283
.. code-block:: python
290284
291285
@pytest.mark.xfail(reason="known parser issue")
292-
def test_function():
293-
...
286+
def test_function(): ...
294287
295288
296289
``raises`` parameter
@@ -302,8 +295,7 @@ a single exception, or a tuple of exceptions, in the ``raises`` argument.
302295
.. code-block:: python
303296
304297
@pytest.mark.xfail(raises=RuntimeError)
305-
def test_function():
306-
...
298+
def test_function(): ...
307299
308300
Then the test will be reported as a regular failure if it fails with an
309301
exception not mentioned in ``raises``.
@@ -317,8 +309,7 @@ even executed, use the ``run`` parameter as ``False``:
317309
.. code-block:: python
318310
319311
@pytest.mark.xfail(run=False)
320-
def test_function():
321-
...
312+
def test_function(): ...
322313
323314
This is specially useful for xfailing tests that are crashing the interpreter and should be
324315
investigated later.
@@ -334,8 +325,7 @@ You can change this by setting the ``strict`` keyword-only parameter to ``True``
334325
.. code-block:: python
335326
336327
@pytest.mark.xfail(strict=True)
337-
def test_function():
338-
...
328+
def test_function(): ...
339329
340330
341331
This will make ``XPASS`` ("unexpectedly passing") results from this test to fail the test suite.

doc/en/reference/reference.rst

+3-6
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ Add warning filters to marked test items.
164164
.. code-block:: python
165165
166166
@pytest.mark.filterwarnings("ignore:.*usage will be deprecated.*:DeprecationWarning")
167-
def test_foo():
168-
...
167+
def test_foo(): ...
169168
170169
171170
.. _`pytest.mark.parametrize ref`:
@@ -276,8 +275,7 @@ For example:
276275
.. code-block:: python
277276
278277
@pytest.mark.timeout(10, "slow", method="thread")
279-
def test_function():
280-
...
278+
def test_function(): ...
281279
282280
Will create and attach a :class:`Mark <pytest.Mark>` object to the collected
283281
:class:`Item <pytest.Item>`, which can then be accessed by fixtures or hooks with
@@ -294,8 +292,7 @@ Example for using multiple custom markers:
294292
295293
@pytest.mark.timeout(10, "slow", method="thread")
296294
@pytest.mark.slow
297-
def test_function():
298-
...
295+
def test_function(): ...
299296
300297
When :meth:`Node.iter_markers <_pytest.nodes.Node.iter_markers>` or :meth:`Node.iter_markers_with_node <_pytest.nodes.Node.iter_markers_with_node>` is used with multiple markers, the marker closest to the function will be iterated over first. The above example will result in ``@pytest.mark.slow`` followed by ``@pytest.mark.timeout(...)``.
301298

0 commit comments

Comments
 (0)