Skip to content

Commit 7f90e74

Browse files
author
boris
committed
label code blocks
1 parent cf7761f commit 7f90e74

23 files changed

+194
-1
lines changed

doc/en/builtin.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
164164
165165
You can also interactively ask for help, e.g. by typing on the Python interactive prompt something like::
166166

167+
.. code-block:: python
168+
167169
import pytest
168170
help(pytest)

doc/en/cache.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Rerunning only failures or failures first
3535

3636
First, let's create 50 test invocation of which only 2 fail::
3737

38+
.. code-block:: python
39+
3840
# content of test_50.py
3941
import pytest
4042
@@ -185,6 +187,8 @@ pytest ``config`` object. Here is a basic example plugin which
185187
implements a :ref:`fixture` which re-uses previously created state
186188
across pytest invocations::
187189

190+
.. code-block:: python
191+
188192
# content of test_caching.py
189193
import pytest
190194
import time

doc/en/capture.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Using print statements for debugging
5151
One primary benefit of the default capturing of stdout/stderr output
5252
is that you can use print statements for debugging::
5353

54+
.. code-block:: python
55+
5456
# content of test_module.py
5557
5658
def setup_function(function):

doc/en/deprecations.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ Internal classes accessed through ``Node``
457457
Access of ``Module``, ``Function``, ``Class``, ``Instance``, ``File`` and ``Item`` through ``Node`` instances now issue
458458
this warning::
459459

460+
.. code-block:: text
461+
460462
usage of Function.Module is deprecated, please use pytest.Module instead
461463
462464
Users should just ``import pytest`` and access those objects using the ``pytest`` module.

doc/en/doctest.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ your own fixtures to provide the tests that use them with context.
193193
``doctest_namespace`` is a standard ``dict`` object into which you
194194
place the objects you want to appear in the doctest namespace::
195195

196+
.. code-block:: python
197+
196198
# content of conftest.py
197199
import numpy
198200
@pytest.fixture(autouse=True)
@@ -201,6 +203,8 @@ place the objects you want to appear in the doctest namespace::
201203
202204
which can then be used in your doctests directly::
203205

206+
.. code-block:: python
207+
204208
# content of numpy.py
205209
def arange():
206210
"""
@@ -221,6 +225,8 @@ Skipping tests dynamically
221225

222226
You can use ``pytest.skip`` to dynamically skip doctests. For example::
223227

228+
.. code-block:: text
229+
224230
>>> import sys, pytest
225231
>>> if sys.platform.startswith('win'):
226232
... pytest.skip('this doctest does not work on Windows')

doc/en/example/parametrize.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ Let's say we want to execute a test with different computation
2121
parameters and the parameter range shall be determined by a command
2222
line argument. Let's first write a simple (do-nothing) computation test::
2323

24+
.. code-block:: python
25+
2426
# content of test_compute.py
2527
2628
def test_compute(param1):
2729
assert param1 < 4
2830
2931
Now we add a test configuration like this::
3032

33+
.. code-block:: python
34+
3135
# content of conftest.py
3236
3337
def pytest_addoption(parser):
@@ -85,6 +89,8 @@ Numbers, strings, booleans and None will have their usual string representation
8589
used in the test ID. For other objects, pytest will make a string based on
8690
the argument name::
8791

92+
.. code-block:: python
93+
8894
# content of test_time.py
8995
9096
import pytest
@@ -173,6 +179,8 @@ an add-on from Robert Collins for the standard unittest framework. We
173179
only have to work a bit to construct the correct arguments for pytest's
174180
:py:func:`Metafunc.parametrize`::
175181

182+
.. code-block:: python
183+
176184
# content of test_scenarios.py
177185
178186
def pytest_generate_tests(metafunc):
@@ -246,6 +254,8 @@ connections or subprocess only when the actual test is run.
246254
Here is a simple example how you can achieve that, first
247255
the actual test requiring a ``db`` object::
248256

257+
.. code-block:: python
258+
249259
# content of test_backends.py
250260
251261
import pytest
@@ -258,6 +268,8 @@ We can now add a test configuration that generates two invocations of
258268
the ``test_db_initialized`` function and also implements a factory that
259269
creates a database object for the actual test invocations::
260270

271+
.. code-block:: python
272+
261273
# content of conftest.py
262274
import pytest
263275
@@ -329,6 +341,8 @@ two fixtures: ``x`` and ``y``. Here we give to indirect the list, which contains
329341
fixture ``x``. The indirect parameter will be applied to this argument only, and the value ``a``
330342
will be passed to respective fixture function::
331343

344+
.. code-block:: python
345+
332346
# content of test_indirect_list.py
333347
334348
import pytest
@@ -372,6 +386,8 @@ Here is an example ``pytest_generate_tests`` function implementing a
372386
parametrization scheme similar to Michael Foord's `unittest
373387
parametrizer`_ but in a lot less code::
374388

389+
.. code-block:: python
390+
375391
# content of ./test_parametrize.py
376392
import pytest
377393
@@ -449,6 +465,8 @@ and get skipped in case the implementation is not importable/available. Let's
449465
say we have a "base" implementation and the other (possibly optimized ones)
450466
need to provide similar results::
451467

468+
.. code-block:: python
469+
452470
# content of conftest.py
453471
454472
import pytest
@@ -463,18 +481,24 @@ need to provide similar results::
463481
464482
And then a base implementation of a simple function::
465483

484+
.. code-block:: python
485+
466486
# content of base.py
467487
def func1():
468488
return 1
469489
470490
And an optimized version::
471491

492+
.. code-block:: python
493+
472494
# content of opt1.py
473495
def func1():
474496
return 1.0001
475497
476498
And finally a little test module::
477499

500+
.. code-block:: python
501+
478502
# content of test_module.py
479503
480504
def test_func1(basemod, optmod):
@@ -581,6 +605,8 @@ in which some tests raise exceptions and others do not.
581605
It is helpful to define a no-op context manager ``does_not_raise`` to serve
582606
as a complement to ``raises``. For example::
583607

608+
.. code-block:: python
609+
584610
from contextlib import contextmanager
585611
import pytest
586612
@@ -606,12 +632,18 @@ while the fourth should raise ``ZeroDivisionError``.
606632
If you're only supporting Python 3.7+, you can simply use ``nullcontext``
607633
to define ``does_not_raise``::
608634

635+
.. code-block:: python
636+
609637
from contextlib import nullcontext as does_not_raise
610638
611639
Or, if you're supporting Python 3.3+ you can use::
612640

641+
.. code-block:: python
642+
613643
from contextlib import ExitStack as does_not_raise
614644
615645
Or, if desired, you can ``pip install contextlib2`` and use::
616646

647+
.. code-block:: python
648+
617649
from contextlib2 import ExitStack as does_not_raise

doc/en/example/pythoncollection.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ This would make ``pytest`` look for tests in files that match the ``check_*
133133
.py`` glob-pattern, ``Check`` prefixes in classes, and functions and methods
134134
that match ``*_check``. For example, if we have::
135135

136+
.. code-block:: python
137+
136138
# content of check_myapp.py
137139
class CheckMyApp(object):
138140
def simple_check(self):
@@ -240,6 +242,8 @@ imported. Moreover, there may files only importable by a specific python
240242
version. For such cases you can dynamically define files to be ignored by
241243
listing them in a ``conftest.py`` file::
242244

245+
.. code-block:: python
246+
243247
# content of conftest.py
244248
import sys
245249
@@ -249,6 +253,8 @@ listing them in a ``conftest.py`` file::
249253
250254
and then if you have a module file like this::
251255

256+
.. code-block:: python
257+
252258
# content of pkg/module_py2.py
253259
def test_only_on_python2():
254260
try:
@@ -258,6 +264,8 @@ and then if you have a module file like this::
258264
259265
and a ``setup.py`` dummy file like this::
260266

267+
.. code-block:: python
268+
261269
# content of setup.py
262270
0/0 # will raise exception if imported
263271
@@ -297,6 +305,8 @@ The following example ``conftest.py`` ignores the file ``setup.py`` and in
297305
addition all files that end with ``*_py2.py`` when executed with a Python 3
298306
interpreter::
299307

308+
.. code-block:: python
309+
300310
# content of conftest.py
301311
import sys
302312

doc/en/example/special.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ function which walks all collected tests and looks
77
if their test class defines a ``callme`` method and
88
calls it::
99

10+
.. code-block:: python
11+
1012
# content of conftest.py
1113
1214
import pytest
@@ -26,6 +28,8 @@ calls it::
2628
test classes may now define a ``callme`` method which
2729
will be called ahead of running any tests::
2830

31+
.. code-block:: python
32+
2933
# content of test_module.py
3034
3135
class TestHello(object):

doc/en/existingtestsuite.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ After pulling the code into your development space using some
1717
flavor of version control and (optionally) setting up a virtualenv
1818
you will want to run::
1919

20+
.. code-block:: bash
21+
2022
cd <repository>
2123
pip install -e . # Environment dependent alternatives include
2224
# 'python setup.py develop' and 'conda develop'

0 commit comments

Comments
 (0)