Skip to content

Commit 0f2d7dc

Browse files
committed
blacken docs
1 parent 5c87800 commit 0f2d7dc

18 files changed

+217
-127
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ repos:
33
- repo: https://github.com/ambv/black
44
rev: 18.4a4
55
hooks:
6-
- id: black
7-
args: [--safe, --quiet]
8-
python_version: python3.6
6+
- id: black
7+
args: [--safe, --quiet]
8+
language_version: python3.6
9+
- repo: https://github.com/asottile/blacken-docs
10+
rev: v0.1.1
11+
hooks:
12+
- id: blacken-docs
13+
additional_dependencies: [black==18.5b1]
14+
language_version: python3.6
915
- repo: https://github.com/pre-commit/pre-commit-hooks
1016
rev: v1.2.3
1117
hooks:

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ An example of a simple test:
4040
def inc(x):
4141
return x + 1
4242
43+
4344
def test_answer():
4445
assert inc(3) == 5
4546

doc/en/capture.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ an example test function that performs some output related checks:
9292

9393
.. code-block:: python
9494
95-
def test_myoutput(capsys): # or use "capfd" for fd-level
95+
def test_myoutput(capsys): # or use "capfd" for fd-level
9696
print("hello")
9797
sys.stderr.write("world\n")
9898
captured = capsys.readouterr()
@@ -145,9 +145,9 @@ as a context manager, disabling capture inside the ``with`` block:
145145
.. code-block:: python
146146
147147
def test_disabling_capturing(capsys):
148-
print('this output is captured')
148+
print("this output is captured")
149149
with capsys.disabled():
150-
print('output not captured, going directly to sys.stdout')
151-
print('this output is also captured')
150+
print("output not captured, going directly to sys.stdout")
151+
print("this output is also captured")
152152
153153
.. include:: links.inc

doc/en/example/attic.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ example: specifying and selecting acceptance tests
99
# ./conftest.py
1010
def pytest_option(parser):
1111
group = parser.getgroup("myproject")
12-
group.addoption("-A", dest="acceptance", action="store_true",
13-
help="run (slow) acceptance tests")
12+
group.addoption(
13+
"-A", dest="acceptance", action="store_true", help="run (slow) acceptance tests"
14+
)
15+
1416

1517
def pytest_funcarg__accept(request):
1618
return AcceptFixture(request)
1719

20+
1821
class AcceptFixture(object):
1922
def __init__(self, request):
20-
if not request.config.getoption('acceptance'):
23+
if not request.config.getoption("acceptance"):
2124
pytest.skip("specify -A to run acceptance tests")
2225
self.tmpdir = request.config.mktemp(request.function.__name__, numbered=True)
2326

@@ -61,6 +64,7 @@ extend the `accept example`_ by putting this in our test module:
6164
arg.tmpdir.mkdir("special")
6265
return arg
6366

67+
6468
class TestSpecialAcceptance(object):
6569
def test_sometest(self, accept):
6670
assert accept.tmpdir.join("special").check()

doc/en/example/simple.rst

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ Here is a basic pattern to achieve this:
1818
# content of test_sample.py
1919
def test_answer(cmdopt):
2020
if cmdopt == "type1":
21-
print ("first")
21+
print("first")
2222
elif cmdopt == "type2":
23-
print ("second")
24-
assert 0 # to see what was printed
23+
print("second")
24+
assert 0 # to see what was printed
2525
2626
2727
For this to work we need to add a command line option and
@@ -32,9 +32,12 @@ provide the ``cmdopt`` through a :ref:`fixture function <fixture function>`:
3232
# content of conftest.py
3333
import pytest
3434
35+
3536
def pytest_addoption(parser):
36-
parser.addoption("--cmdopt", action="store", default="type1",
37-
help="my option: type1 or type2")
37+
parser.addoption(
38+
"--cmdopt", action="store", default="type1", help="my option: type1 or type2"
39+
)
40+
3841
3942
@pytest.fixture
4043
def cmdopt(request):
@@ -102,9 +105,12 @@ the command line arguments before they get processed:
102105
103106
# content of conftest.py
104107
import sys
108+
109+
105110
def pytest_load_initial_conftests(args):
106-
if 'xdist' in sys.modules: # pytest-xdist plugin
111+
if "xdist" in sys.modules: # pytest-xdist plugin
107112
import multiprocessing
113+
108114
num = max(multiprocessing.cpu_count() / 2, 1)
109115
args[:] = ["-n", str(num)] + args
110116
@@ -136,9 +142,13 @@ line option to control skipping of ``pytest.mark.slow`` marked tests:
136142
# content of conftest.py
137143
138144
import pytest
145+
146+
139147
def pytest_addoption(parser):
140-
parser.addoption("--runslow", action="store_true",
141-
default=False, help="run slow tests")
148+
parser.addoption(
149+
"--runslow", action="store_true", default=False, help="run slow tests"
150+
)
151+
142152
143153
def pytest_collection_modifyitems(config, items):
144154
if config.getoption("--runslow"):
@@ -206,10 +216,13 @@ Example:
206216
207217
# content of test_checkconfig.py
208218
import pytest
219+
220+
209221
def checkconfig(x):
210222
__tracebackhide__ = True
211223
if not hasattr(x, "config"):
212-
pytest.fail("not configured: %s" %(x,))
224+
pytest.fail("not configured: %s" % (x,))
225+
213226
214227
def test_something():
215228
checkconfig(42)
@@ -240,13 +253,16 @@ this to make sure unexpected exception types aren't hidden:
240253
import operator
241254
import pytest
242255
256+
243257
class ConfigException(Exception):
244258
pass
245259
260+
246261
def checkconfig(x):
247-
__tracebackhide__ = operator.methodcaller('errisinstance', ConfigException)
262+
__tracebackhide__ = operator.methodcaller("errisinstance", ConfigException)
248263
if not hasattr(x, "config"):
249-
raise ConfigException("not configured: %s" %(x,))
264+
raise ConfigException("not configured: %s" % (x,))
265+
250266
251267
def test_something():
252268
checkconfig(42)
@@ -269,19 +285,23 @@ running from a test you can do something like this:
269285
270286
# content of conftest.py
271287
288+
272289
def pytest_configure(config):
273290
import sys
291+
274292
sys._called_from_test = True
275293
294+
276295
def pytest_unconfigure(config):
277296
import sys
297+
278298
del sys._called_from_test
279299
280300
and then check for the ``sys._called_from_test`` flag:
281301

282302
.. code-block:: python
283303
284-
if hasattr(sys, '_called_from_test'):
304+
if hasattr(sys, "_called_from_test"):
285305
# called from within a test run
286306
...
287307
else:
@@ -303,6 +323,7 @@ It's easy to present extra information in a ``pytest`` run:
303323
304324
# content of conftest.py
305325
326+
306327
def pytest_report_header(config):
307328
return "project deps: mylib-1.1"
308329
@@ -327,8 +348,9 @@ display more information if applicable:
327348
328349
# content of conftest.py
329350
351+
330352
def pytest_report_header(config):
331-
if config.getoption('verbose') > 0:
353+
if config.getoption("verbose") > 0:
332354
return ["info1: did you know that ...", "did you?"]
333355
334356
which will add info only when run with "--v"::
@@ -369,12 +391,15 @@ out which tests are the slowest. Let's make an artificial test suite:
369391
# content of test_some_are_slow.py
370392
import time
371393
394+
372395
def test_funcfast():
373396
time.sleep(0.1)
374397
398+
375399
def test_funcslow1():
376400
time.sleep(0.2)
377401
402+
378403
def test_funcslow2():
379404
time.sleep(0.3)
380405
@@ -411,17 +436,19 @@ an ``incremental`` marker which is to be used on classes:
411436
412437
import pytest
413438
439+
414440
def pytest_runtest_makereport(item, call):
415441
if "incremental" in item.keywords:
416442
if call.excinfo is not None:
417443
parent = item.parent
418444
parent._previousfailed = item
419445
446+
420447
def pytest_runtest_setup(item):
421448
if "incremental" in item.keywords:
422449
previousfailed = getattr(item.parent, "_previousfailed", None)
423450
if previousfailed is not None:
424-
pytest.xfail("previous test failed (%s)" %previousfailed.name)
451+
pytest.xfail("previous test failed (%s)" % previousfailed.name)
425452
426453
These two hook implementations work together to abort incremental-marked
427454
tests in a class. Here is a test module example:
@@ -432,15 +459,19 @@ tests in a class. Here is a test module example:
432459
433460
import pytest
434461
462+
435463
@pytest.mark.incremental
436464
class TestUserHandling(object):
437465
def test_login(self):
438466
pass
467+
439468
def test_modification(self):
440469
assert 0
470+
441471
def test_deletion(self):
442472
pass
443473
474+
444475
def test_normal():
445476
pass
446477
@@ -491,9 +522,11 @@ Here is an example for making a ``db`` fixture available in a directory:
491522
# content of a/conftest.py
492523
import pytest
493524
525+
494526
class DB(object):
495527
pass
496528
529+
497530
@pytest.fixture(scope="session")
498531
def db():
499532
return DB()
@@ -602,6 +635,7 @@ case we just write some information out to a ``failures`` file:
602635
import pytest
603636
import os.path
604637
638+
605639
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
606640
def pytest_runtest_makereport(item, call):
607641
# execute all other hooks to obtain the report object
@@ -628,6 +662,8 @@ if you then have failing tests:
628662
# content of test_module.py
629663
def test_fail1(tmpdir):
630664
assert 0
665+
666+
631667
def test_fail2():
632668
assert 0
633669
@@ -680,6 +716,7 @@ here is a little example implemented via a local plugin:
680716
681717
import pytest
682718
719+
683720
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
684721
def pytest_runtest_makereport(item, call):
685722
# execute all other hooks to obtain the report object
@@ -698,10 +735,10 @@ here is a little example implemented via a local plugin:
698735
# request.node is an "item" because we use the default
699736
# "function" scope
700737
if request.node.rep_setup.failed:
701-
print ("setting up a test failed!", request.node.nodeid)
738+
print("setting up a test failed!", request.node.nodeid)
702739
elif request.node.rep_setup.passed:
703740
if request.node.rep_call.failed:
704-
print ("executing test failed", request.node.nodeid)
741+
print("executing test failed", request.node.nodeid)
705742
706743
707744
if you then have failing tests:
@@ -712,16 +749,20 @@ if you then have failing tests:
712749
713750
import pytest
714751
752+
715753
@pytest.fixture
716754
def other():
717755
assert 0
718756
757+
719758
def test_setup_fails(something, other):
720759
pass
721760
761+
722762
def test_call_fails(something):
723763
assert 0
724764
765+
725766
def test_fail2():
726767
assert 0
727768
@@ -789,7 +830,7 @@ test got stuck if necessary:
789830
790831
for pid in psutil.pids():
791832
environ = psutil.Process(pid).environ()
792-
if 'PYTEST_CURRENT_TEST' in environ:
833+
if "PYTEST_CURRENT_TEST" in environ:
793834
print(f'pytest process {pid} running: {environ["PYTEST_CURRENT_TEST"]}')
794835
795836
During the test session pytest will set ``PYTEST_CURRENT_TEST`` to the current test
@@ -843,8 +884,9 @@ like ``pytest-timeout`` they must be imported explicitly and passed on to pytest
843884
import sys
844885
import pytest_timeout # Third party plugin
845886
846-
if len(sys.argv) > 1 and sys.argv[1] == '--pytest':
887+
if len(sys.argv) > 1 and sys.argv[1] == "--pytest":
847888
import pytest
889+
848890
sys.exit(pytest.main(sys.argv[2:], plugins=[pytest_timeout]))
849891
else:
850892
# normal application execution: at this point argv can be parsed

0 commit comments

Comments
 (0)