Skip to content

Commit 5f95dce

Browse files
author
boris
committed
ran blacken-docs
1 parent 75d0b89 commit 5f95dce

17 files changed

+163
-66
lines changed

doc/en/assert.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ 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: {} != {}".format(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

doc/en/builtin.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,5 @@ You can also interactively ask for help, e.g. by typing on the Python interactiv
167167
.. code-block:: python
168168
169169
import pytest
170+
170171
help(pytest)

doc/en/cache.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ First, let's create 50 test invocation of which only 2 fail::
4040
# content of test_50.py
4141
import pytest
4242
43+
4344
@pytest.mark.parametrize("i", range(50))
4445
def test_num(i):
4546
if i in (17, 25):
46-
pytest.fail("bad luck")
47+
pytest.fail("bad luck")
4748
4849
If you run this for the first time you will see two failures:
4950

@@ -193,9 +194,11 @@ across pytest invocations::
193194
import pytest
194195
import time
195196
197+
196198
def expensive_computation():
197199
print("running expensive computation...")
198200
201+
199202
@pytest.fixture
200203
def mydata(request):
201204
val = request.config.cache.get("example/value", None)
@@ -205,6 +208,7 @@ across pytest invocations::
205208
request.config.cache.set("example/value", val)
206209
return val
207210
211+
208212
def test_function(mydata):
209213
assert mydata == 23
210214

doc/en/capture.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ is that you can use print statements for debugging::
5555
5656
# content of test_module.py
5757
58+
5859
def setup_function(function):
5960
print("setting up %s" % function)
6061
62+
6163
def test_func1():
6264
assert True
6365
66+
6467
def test_func2():
6568
assert False
6669

doc/en/doctest.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,11 @@ place the objects you want to appear in the doctest namespace::
197197
198198
# content of conftest.py
199199
import numpy
200+
201+
200202
@pytest.fixture(autouse=True)
201203
def add_np(doctest_namespace):
202-
doctest_namespace['np'] = numpy
204+
doctest_namespace["np"] = numpy
203205
204206
which can then be used in your doctests directly::
205207

doc/en/example/parametrize.rst

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ line argument. Let's first write a simple (do-nothing) computation test::
2525
2626
# content of test_compute.py
2727
28+
2829
def test_compute(param1):
2930
assert param1 < 4
3031
@@ -34,13 +35,14 @@ Now we add a test configuration like this::
3435
3536
# content of conftest.py
3637
38+
3739
def pytest_addoption(parser):
38-
parser.addoption("--all", action="store_true",
39-
help="run all combinations")
40+
parser.addoption("--all", action="store_true", help="run all combinations")
41+
4042
4143
def pytest_generate_tests(metafunc):
42-
if 'param1' in metafunc.fixturenames:
43-
if metafunc.config.getoption('all'):
44+
if "param1" in metafunc.fixturenames:
45+
if metafunc.config.getoption("all"):
4446
end = 5
4547
else:
4648
end = 2
@@ -118,20 +120,26 @@ the argument name::
118120
def idfn(val):
119121
if isinstance(val, (datetime,)):
120122
# note this wouldn't show any hours/minutes/seconds
121-
return val.strftime('%Y%m%d')
123+
return val.strftime("%Y%m%d")
122124
123125
124126
@pytest.mark.parametrize("a,b,expected", testdata, ids=idfn)
125127
def test_timedistance_v2(a, b, expected):
126128
diff = a - b
127129
assert diff == expected
128130
129-
@pytest.mark.parametrize("a,b,expected", [
130-
pytest.param(datetime(2001, 12, 12), datetime(2001, 12, 11),
131-
timedelta(1), id='forward'),
132-
pytest.param(datetime(2001, 12, 11), datetime(2001, 12, 12),
133-
timedelta(-1), id='backward'),
134-
])
131+
132+
@pytest.mark.parametrize(
133+
"a,b,expected",
134+
[
135+
pytest.param(
136+
datetime(2001, 12, 12), datetime(2001, 12, 11), timedelta(1), id="forward"
137+
),
138+
pytest.param(
139+
datetime(2001, 12, 11), datetime(2001, 12, 12), timedelta(-1), id="backward"
140+
),
141+
],
142+
)
135143
def test_timedistance_v3(a, b, expected):
136144
diff = a - b
137145
assert diff == expected
@@ -183,6 +191,7 @@ only have to work a bit to construct the correct arguments for pytest's
183191
184192
# content of test_scenarios.py
185193
194+
186195
def pytest_generate_tests(metafunc):
187196
idlist = []
188197
argvalues = []
@@ -193,8 +202,10 @@ only have to work a bit to construct the correct arguments for pytest's
193202
argvalues.append([x[1] for x in items])
194203
metafunc.parametrize(argnames, argvalues, ids=idlist, scope="class")
195204
196-
scenario1 = ('basic', {'attribute': 'value'})
197-
scenario2 = ('advanced', {'attribute': 'value2'})
205+
206+
scenario1 = ("basic", {"attribute": "value"})
207+
scenario2 = ("advanced", {"attribute": "value2"})
208+
198209
199210
class TestSampleWithScenarios:
200211
scenarios = [scenario1, scenario2]
@@ -259,6 +270,8 @@ the actual test requiring a ``db`` object::
259270
# content of test_backends.py
260271
261272
import pytest
273+
274+
262275
def test_db_initialized(db):
263276
# a dummy test
264277
if db.__class__.__name__ == "DB2":
@@ -273,15 +286,20 @@ creates a database object for the actual test invocations::
273286
# content of conftest.py
274287
import pytest
275288
289+
276290
def pytest_generate_tests(metafunc):
277-
if 'db' in metafunc.fixturenames:
278-
metafunc.parametrize("db", ['d1', 'd2'], indirect=True)
291+
if "db" in metafunc.fixturenames:
292+
metafunc.parametrize("db", ["d1", "d2"], indirect=True)
293+
279294
280295
class DB1:
281296
"one database object"
297+
298+
282299
class DB2:
283300
"alternative database object"
284301
302+
285303
@pytest.fixture
286304
def db(request):
287305
if request.param == "d1":
@@ -346,18 +364,22 @@ will be passed to respective fixture function::
346364
# content of test_indirect_list.py
347365
348366
import pytest
349-
@pytest.fixture(scope='function')
367+
368+
369+
@pytest.fixture(scope="function")
350370
def x(request):
351371
return request.param * 3
352372
353-
@pytest.fixture(scope='function')
373+
374+
@pytest.fixture(scope="function")
354375
def y(request):
355376
return request.param * 2
356377
357-
@pytest.mark.parametrize('x, y', [('a', 'b')], indirect=['x'])
358-
def test_indirect(x,y):
359-
assert x == 'aaa'
360-
assert y == 'b'
378+
379+
@pytest.mark.parametrize("x, y", [("a", "b")], indirect=["x"])
380+
def test_indirect(x, y):
381+
assert x == "aaa"
382+
assert y == "b"
361383
362384
The result of this test will be successful:
363385

@@ -391,18 +413,21 @@ parametrizer`_ but in a lot less code::
391413
# content of ./test_parametrize.py
392414
import pytest
393415
416+
394417
def pytest_generate_tests(metafunc):
395418
# called once per each test function
396419
funcarglist = metafunc.cls.params[metafunc.function.__name__]
397420
argnames = sorted(funcarglist[0])
398-
metafunc.parametrize(argnames, [[funcargs[name] for name in argnames]
399-
for funcargs in funcarglist])
421+
metafunc.parametrize(
422+
argnames, [[funcargs[name] for name in argnames] for funcargs in funcarglist]
423+
)
424+
400425
401426
class TestClass:
402427
# a map specifying multiple argument sets for a test method
403428
params = {
404-
'test_equals': [dict(a=1, b=2), dict(a=3, b=3), ],
405-
'test_zerodivision': [dict(a=1, b=0), ],
429+
"test_equals": [dict(a=1, b=2), dict(a=3, b=3)],
430+
"test_zerodivision": [dict(a=1, b=0)],
406431
}
407432
408433
def test_equals(self, a, b):
@@ -471,10 +496,12 @@ need to provide similar results::
471496
472497
import pytest
473498
499+
474500
@pytest.fixture(scope="session")
475501
def basemod(request):
476502
return pytest.importorskip("base")
477503
504+
478505
@pytest.fixture(scope="session", params=["opt1", "opt2"])
479506
def optmod(request):
480507
return pytest.importorskip(request.param)
@@ -501,6 +528,7 @@ And finally a little test module::
501528
502529
# content of test_module.py
503530
531+
504532
def test_func1(basemod, optmod):
505533
assert round(basemod.func1(), 3) == round(optmod.func1(), 3)
506534
@@ -610,17 +638,21 @@ as a complement to ``raises``. For example::
610638
from contextlib import contextmanager
611639
import pytest
612640
641+
613642
@contextmanager
614643
def does_not_raise():
615644
yield
616645
617646
618-
@pytest.mark.parametrize('example_input,expectation', [
619-
(3, does_not_raise()),
620-
(2, does_not_raise()),
621-
(1, does_not_raise()),
622-
(0, pytest.raises(ZeroDivisionError)),
623-
])
647+
@pytest.mark.parametrize(
648+
"example_input,expectation",
649+
[
650+
(3, does_not_raise()),
651+
(2, does_not_raise()),
652+
(1, does_not_raise()),
653+
(0, pytest.raises(ZeroDivisionError)),
654+
],
655+
)
624656
def test_division(example_input, expectation):
625657
"""Test how much I know division."""
626658
with expectation:

doc/en/example/pythoncollection.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ that match ``*_check``. For example, if we have::
139139
class CheckMyApp:
140140
def simple_check(self):
141141
pass
142+
142143
def complex_check(self):
143144
pass
144145
@@ -267,7 +268,7 @@ and a ``setup.py`` dummy file like this::
267268
.. code-block:: python
268269
269270
# content of setup.py
270-
0/0 # will raise exception if imported
271+
0 / 0 # will raise exception if imported
271272
272273
If you run with a Python 2 interpreter then you will find the one test and will
273274
leave out the ``setup.py`` file:

doc/en/example/special.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ calls it::
1313
1414
import pytest
1515
16+
1617
@pytest.fixture(scope="session", autouse=True)
1718
def callattr_ahead_of_alltests(request):
1819
print("callattr_ahead_of_alltests called")
@@ -22,7 +23,7 @@ calls it::
2223
cls = item.getparent(pytest.Class)
2324
if cls not in seen:
2425
if hasattr(cls.obj, "callme"):
25-
cls.obj.callme()
26+
cls.obj.callme()
2627
seen.add(cls)
2728
2829
test classes may now define a ``callme`` method which
@@ -32,6 +33,7 @@ will be called ahead of running any tests::
3233
3334
# content of test_module.py
3435
36+
3537
class TestHello:
3638
@classmethod
3739
def callme(cls):
@@ -43,16 +45,20 @@ will be called ahead of running any tests::
4345
def test_method2(self):
4446
print("test_method1 called")
4547
48+
4649
class TestOther:
4750
@classmethod
4851
def callme(cls):
4952
print("callme other called")
53+
5054
def test_other(self):
5155
print("test other")
5256
57+
5358
# works with unittest as well ...
5459
import unittest
5560
61+
5662
class SomeTest(unittest.TestCase):
5763
@classmethod
5864
def callme(self):

0 commit comments

Comments
 (0)