Skip to content

Commit 6c8d8a9

Browse files
authored
pyupgrade docs to Python 3 (#5705)
pyupgrade docs to Python 3
2 parents 28fabc5 + 78de9d4 commit 6c8d8a9

29 files changed

+491
-201
lines changed

doc/en/assert.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,17 @@ file which provides an alternative explanation for ``Foo`` objects:
238238
239239
def pytest_assertrepr_compare(op, left, right):
240240
if isinstance(left, Foo) and isinstance(right, Foo) and op == "==":
241-
return ["Comparing Foo instances:", " vals: %s != %s" % (left.val, right.val)]
241+
return [
242+
"Comparing Foo instances:",
243+
" vals: {} != {}".format(left.val, right.val),
244+
]
242245
243246
now, given this test module:
244247

245248
.. code-block:: python
246249
247250
# content of test_foocompare.py
248-
class Foo(object):
251+
class Foo:
249252
def __init__(self, val):
250253
self.val = val
251254

doc/en/builtin.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
162162
163163
no tests ran in 0.12 seconds
164164
165-
You can also interactively ask for help, e.g. by typing on the Python interactive prompt something like::
165+
You can also interactively ask for help, e.g. by typing on the Python interactive prompt something like:
166+
167+
.. code-block:: python
166168
167169
import pytest
170+
168171
help(pytest)

doc/en/cache.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ Other plugins may access the `config.cache`_ object to set/get
3333
Rerunning only failures or failures first
3434
-----------------------------------------------
3535

36-
First, let's create 50 test invocation of which only 2 fail::
36+
First, let's create 50 test invocation of which only 2 fail:
37+
38+
.. code-block:: python
3739
3840
# content of test_50.py
3941
import pytest
4042
43+
4144
@pytest.mark.parametrize("i", range(50))
4245
def test_num(i):
4346
if i in (17, 25):
44-
pytest.fail("bad luck")
47+
pytest.fail("bad luck")
4548
4649
If you run this for the first time you will see two failures:
4750

@@ -183,15 +186,19 @@ The new config.cache object
183186
Plugins or conftest.py support code can get a cached value using the
184187
pytest ``config`` object. Here is a basic example plugin which
185188
implements a :ref:`fixture` which re-uses previously created state
186-
across pytest invocations::
189+
across pytest invocations:
190+
191+
.. code-block:: python
187192
188193
# content of test_caching.py
189194
import pytest
190195
import time
191196
197+
192198
def expensive_computation():
193199
print("running expensive computation...")
194200
201+
195202
@pytest.fixture
196203
def mydata(request):
197204
val = request.config.cache.get("example/value", None)
@@ -201,6 +208,7 @@ across pytest invocations::
201208
request.config.cache.set("example/value", val)
202209
return val
203210
211+
204212
def test_function(mydata):
205213
assert mydata == 23
206214

doc/en/capture.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,21 @@ Using print statements for debugging
4949
---------------------------------------------------
5050

5151
One primary benefit of the default capturing of stdout/stderr output
52-
is that you can use print statements for debugging::
52+
is that you can use print statements for debugging:
53+
54+
.. code-block:: python
5355
5456
# content of test_module.py
5557
58+
5659
def setup_function(function):
5760
print("setting up %s" % function)
5861
62+
5963
def test_func1():
6064
assert True
6165
66+
6267
def test_func2():
6368
assert False
6469

doc/en/deprecations.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,9 @@ Internal classes accessed through ``Node``
455455
.. versionremoved:: 4.0
456456

457457
Access of ``Module``, ``Function``, ``Class``, ``Instance``, ``File`` and ``Item`` through ``Node`` instances now issue
458-
this warning::
458+
this warning:
459+
460+
.. code-block:: text
459461
460462
usage of Function.Module is deprecated, please use pytest.Module instead
461463

doc/en/doctest.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,21 @@ namespace in which your doctests run. It is intended to be used within
191191
your own fixtures to provide the tests that use them with context.
192192

193193
``doctest_namespace`` is a standard ``dict`` object into which you
194-
place the objects you want to appear in the doctest namespace::
194+
place the objects you want to appear in the doctest namespace:
195+
196+
.. code-block:: python
195197
196198
# content of conftest.py
197199
import numpy
200+
201+
198202
@pytest.fixture(autouse=True)
199203
def add_np(doctest_namespace):
200-
doctest_namespace['np'] = numpy
204+
doctest_namespace["np"] = numpy
201205
202-
which can then be used in your doctests directly::
206+
which can then be used in your doctests directly:
207+
208+
.. code-block:: python
203209
204210
# content of numpy.py
205211
def arange():
@@ -219,7 +225,9 @@ Skipping tests dynamically
219225

220226
.. versionadded:: 4.4
221227

222-
You can use ``pytest.skip`` to dynamically skip doctests. For example::
228+
You can use ``pytest.skip`` to dynamically skip doctests. For example:
229+
230+
.. code-block:: text
223231
224232
>>> import sys, pytest
225233
>>> if sys.platform.startswith('win'):

doc/en/example/attic.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ example: specifying and selecting acceptance tests
1818
return AcceptFixture(request)
1919

2020

21-
class AcceptFixture(object):
21+
class AcceptFixture:
2222
def __init__(self, request):
2323
if not request.config.getoption("acceptance"):
2424
pytest.skip("specify -A to run acceptance tests")
@@ -65,7 +65,7 @@ extend the `accept example`_ by putting this in our test module:
6565
return arg
6666

6767

68-
class TestSpecialAcceptance(object):
68+
class TestSpecialAcceptance:
6969
def test_sometest(self, accept):
7070
assert accept.tmpdir.join("special").check()
7171

doc/en/example/markers.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ You can "mark" a test function with custom metadata like this:
3333
pass
3434
3535
36-
class TestClass(object):
36+
class TestClass:
3737
def test_method(self):
3838
pass
3939
@@ -278,7 +278,7 @@ its test methods:
278278
279279
280280
@pytest.mark.webtest
281-
class TestClass(object):
281+
class TestClass:
282282
def test_startup(self):
283283
pass
284284
@@ -295,7 +295,7 @@ Due to legacy reasons, it is possible to set the ``pytestmark`` attribute on a T
295295
import pytest
296296
297297
298-
class TestClass(object):
298+
class TestClass:
299299
pytestmark = pytest.mark.webtest
300300
301301
or if you need to use multiple markers you can use a list:
@@ -305,7 +305,7 @@ or if you need to use multiple markers you can use a list:
305305
import pytest
306306
307307
308-
class TestClass(object):
308+
class TestClass:
309309
pytestmark = [pytest.mark.webtest, pytest.mark.slowtest]
310310
311311
You can also set a module level marker::
@@ -523,7 +523,7 @@ code you can read over all such settings. Example:
523523
524524
525525
@pytest.mark.glob("class", x=2)
526-
class TestClass(object):
526+
class TestClass:
527527
@pytest.mark.glob("function", x=3)
528528
def test_something(self):
529529
pass
@@ -539,7 +539,7 @@ test function. From a conftest file we can read it like this:
539539
540540
def pytest_runtest_setup(item):
541541
for mark in item.iter_markers(name="glob"):
542-
print("glob args=%s kwargs=%s" % (mark.args, mark.kwargs))
542+
print("glob args={} kwargs={}".format(mark.args, mark.kwargs))
543543
sys.stdout.flush()
544544
545545
Let's run this without capturing output and see what we get:

0 commit comments

Comments
 (0)