Skip to content

Commit 4546d54

Browse files
Upgrade blacken-doc to black's 2024 style (#11899)
1 parent de161f8 commit 4546d54

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
@@ -33,13 +33,11 @@ have been available since years and should be used instead.
3333
.. code-block:: python
3434
3535
@pytest.mark.tryfirst
36-
def pytest_runtest_call():
37-
...
36+
def pytest_runtest_call(): ...
3837
3938
4039
# or
41-
def pytest_runtest_call():
42-
...
40+
def pytest_runtest_call(): ...
4341
4442
4543
pytest_runtest_call.tryfirst = True
@@ -49,8 +47,7 @@ should be changed to:
4947
.. code-block:: python
5048
5149
@pytest.hookimpl(tryfirst=True)
52-
def pytest_runtest_call():
53-
...
50+
def pytest_runtest_call(): ...
5451
5552
Changed ``hookimpl`` attributes:
5653

@@ -146,8 +143,7 @@ Applying a mark to a fixture function never had any effect, but it is a common u
146143
147144
@pytest.mark.usefixtures("clean_database")
148145
@pytest.fixture
149-
def user() -> User:
150-
...
146+
def user() -> User: ...
151147
152148
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.
153149

@@ -308,11 +304,9 @@ they are in fact part of the ``nose`` support.
308304
def teardown(self):
309305
self.resource.close()
310306
311-
def test_foo(self):
312-
...
307+
def test_foo(self): ...
313308
314-
def test_bar(self):
315-
...
309+
def test_bar(self): ...
316310
317311
318312
@@ -327,11 +321,9 @@ Native pytest support uses ``setup_method`` and ``teardown_method`` (see :ref:`x
327321
def teardown_method(self):
328322
self.resource.close()
329323
330-
def test_foo(self):
331-
...
324+
def test_foo(self): ...
332325
333-
def test_bar(self):
334-
...
326+
def test_bar(self): ...
335327
336328
337329
This is easy to do in an entire code base by doing a simple find/replace.
@@ -346,17 +338,14 @@ Code using `@with_setup <with-setup-nose>`_ such as this:
346338
from nose.tools import with_setup
347339
348340
349-
def setup_some_resource():
350-
...
341+
def setup_some_resource(): ...
351342
352343
353-
def teardown_some_resource():
354-
...
344+
def teardown_some_resource(): ...
355345
356346
357347
@with_setup(setup_some_resource, teardown_some_resource)
358-
def test_foo():
359-
...
348+
def test_foo(): ...
360349
361350
Will also need to be ported to a supported pytest style. One way to do it is using a fixture:
362351

@@ -365,12 +354,10 @@ Will also need to be ported to a supported pytest style. One way to do it is usi
365354
import pytest
366355
367356
368-
def setup_some_resource():
369-
...
357+
def setup_some_resource(): ...
370358
371359
372-
def teardown_some_resource():
373-
...
360+
def teardown_some_resource(): ...
374361
375362
376363
@pytest.fixture
@@ -380,8 +367,7 @@ Will also need to be ported to a supported pytest style. One way to do it is usi
380367
teardown_some_resource()
381368
382369
383-
def test_foo(some_resource):
384-
...
370+
def test_foo(some_resource): ...
385371
386372
387373
.. _`with-setup-nose`: https://nose.readthedocs.io/en/latest/testing_tools.html?highlight=with_setup#nose.tools.with_setup
@@ -500,17 +486,15 @@ Implement the :hook:`pytest_load_initial_conftests` hook instead.
500486

501487
.. code-block:: python
502488
503-
def pytest_cmdline_preparse(config: Config, args: List[str]) -> None:
504-
...
489+
def pytest_cmdline_preparse(config: Config, args: List[str]) -> None: ...
505490
506491
507492
# becomes:
508493
509494
510495
def pytest_load_initial_conftests(
511496
early_config: Config, parser: Parser, args: List[str]
512-
) -> None:
513-
...
497+
) -> None: ...
514498
515499
516500
Collection changes in pytest 8
@@ -925,8 +909,7 @@ Applying marks to values of a ``pytest.mark.parametrize`` call is now deprecated
925909
(50, 500),
926910
],
927911
)
928-
def test_foo(a, b):
929-
...
912+
def test_foo(a, b): ...
930913
931914
This code applies the ``pytest.mark.xfail(reason="flaky")`` mark to the ``(6, 36)`` value of the above parametrization
932915
call.
@@ -949,8 +932,7 @@ To update the code, use ``pytest.param``:
949932
(50, 500),
950933
],
951934
)
952-
def test_foo(a, b):
953-
...
935+
def test_foo(a, b): ...
954936
955937
956938
.. _pytest_funcarg__ prefix deprecated:
@@ -1101,15 +1083,13 @@ This is just a matter of renaming the fixture as the API is the same:
11011083

11021084
.. code-block:: python
11031085
1104-
def test_foo(record_xml_property):
1105-
...
1086+
def test_foo(record_xml_property): ...
11061087
11071088
Change to:
11081089

11091090
.. code-block:: python
11101091
1111-
def test_foo(record_property):
1112-
...
1092+
def test_foo(record_property): ...
11131093
11141094
11151095
.. _passing command-line string to pytest.main deprecated:
@@ -1271,8 +1251,7 @@ Example of usage:
12711251

12721252
.. code-block:: python
12731253
1274-
class MySymbol:
1275-
...
1254+
class MySymbol: ...
12761255
12771256
12781257
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)