pytest-codeblock 0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytest_codeblock-0.1/LICENSE +21 -0
- pytest_codeblock-0.1/PKG-INFO +323 -0
- pytest_codeblock-0.1/README.rst +268 -0
- pytest_codeblock-0.1/pyproject.toml +195 -0
- pytest_codeblock-0.1/pytest_codeblock/__init__.py +24 -0
- pytest_codeblock-0.1/pytest_codeblock/collector.py +68 -0
- pytest_codeblock-0.1/pytest_codeblock/constants.py +15 -0
- pytest_codeblock-0.1/pytest_codeblock/md.py +161 -0
- pytest_codeblock-0.1/pytest_codeblock/rst.py +210 -0
- pytest_codeblock-0.1/pytest_codeblock.egg-info/PKG-INFO +323 -0
- pytest_codeblock-0.1/pytest_codeblock.egg-info/SOURCES.txt +14 -0
- pytest_codeblock-0.1/pytest_codeblock.egg-info/dependency_links.txt +1 -0
- pytest_codeblock-0.1/pytest_codeblock.egg-info/entry_points.txt +2 -0
- pytest_codeblock-0.1/pytest_codeblock.egg-info/requires.txt +31 -0
- pytest_codeblock-0.1/pytest_codeblock.egg-info/top_level.txt +1 -0
- pytest_codeblock-0.1/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Artur Barseghyan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pytest-codeblock
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Pytest plugin to collect and test code blocks in reStructuredText and Markdown files.
|
|
5
|
+
Author-email: Artur Barseghyan <artur.barseghyan@gmail.com>
|
|
6
|
+
Maintainer-email: Artur Barseghyan <artur.barseghyan@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/barseghyanartur/pytest-codeblock/
|
|
9
|
+
Project-URL: Repository, https://github.com/barseghyanartur/pytest-codeblock/
|
|
10
|
+
Project-URL: Issues, https://github.com/barseghyanartur/pytest-codeblock/issues
|
|
11
|
+
Project-URL: Documentation, https://pytest-codeblock.readthedocs.io/
|
|
12
|
+
Project-URL: Changelog, https://pytest-codeblock.readthedocs.io/en/latest/changelog.html
|
|
13
|
+
Keywords: pytest,plugin,documentation,code blocks,markdown,rst
|
|
14
|
+
Classifier: Framework :: Pytest
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python
|
|
23
|
+
Classifier: Topic :: Software Development :: Testing
|
|
24
|
+
Classifier: Topic :: Software Development
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/x-rst
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: pytest
|
|
29
|
+
Provides-Extra: all
|
|
30
|
+
Requires-Dist: pytest-codeblock[build,dev,docs,test]; extra == "all"
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: detect-secrets; extra == "dev"
|
|
33
|
+
Requires-Dist: doc8; extra == "dev"
|
|
34
|
+
Requires-Dist: ipython; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy; extra == "dev"
|
|
36
|
+
Requires-Dist: pydoclint; extra == "dev"
|
|
37
|
+
Requires-Dist: ruff; extra == "dev"
|
|
38
|
+
Requires-Dist: twine; extra == "dev"
|
|
39
|
+
Requires-Dist: uv; extra == "dev"
|
|
40
|
+
Provides-Extra: test
|
|
41
|
+
Requires-Dist: django; extra == "test"
|
|
42
|
+
Requires-Dist: pytest; extra == "test"
|
|
43
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
44
|
+
Requires-Dist: pytest-django; extra == "test"
|
|
45
|
+
Provides-Extra: docs
|
|
46
|
+
Requires-Dist: sphinx<6.0; extra == "docs"
|
|
47
|
+
Requires-Dist: sphinx-autobuild; extra == "docs"
|
|
48
|
+
Requires-Dist: sphinx-rtd-theme>=1.3.0; extra == "docs"
|
|
49
|
+
Requires-Dist: sphinx-no-pragma; extra == "docs"
|
|
50
|
+
Provides-Extra: build
|
|
51
|
+
Requires-Dist: build; extra == "build"
|
|
52
|
+
Requires-Dist: twine; extra == "build"
|
|
53
|
+
Requires-Dist: wheel; extra == "build"
|
|
54
|
+
Dynamic: license-file
|
|
55
|
+
|
|
56
|
+
================
|
|
57
|
+
pytest-codeblock
|
|
58
|
+
================
|
|
59
|
+
|
|
60
|
+
.. External references
|
|
61
|
+
.. _reStructuredText: https://docutils.sourceforge.io/rst.html
|
|
62
|
+
.. _Markdown: https://daringfireball.net/projects/markdown/
|
|
63
|
+
.. _pytest: https://docs.pytest.org
|
|
64
|
+
.. _Django: https://www.djangoproject.com
|
|
65
|
+
.. _pip: https://pypi.org/project/pip/
|
|
66
|
+
.. _uv: https://pypi.org/project/uv/
|
|
67
|
+
|
|
68
|
+
.. Internal references
|
|
69
|
+
|
|
70
|
+
.. _pytest-codeblock: https://github.com/barseghyanartur/pytest-codeblock/
|
|
71
|
+
.. _Read the Docs: http://pytest-codeblock.readthedocs.io/
|
|
72
|
+
.. _Examples: https://github.com/barseghyanartur/pytest-codeblock/tree/main/examples
|
|
73
|
+
.. _Contributor guidelines: https://pytest-codeblock.readthedocs.io/en/latest/contributor_guidelines.html
|
|
74
|
+
|
|
75
|
+
Test your code blocks.
|
|
76
|
+
|
|
77
|
+
.. image:: https://img.shields.io/pypi/v/pytest-codeblock.svg
|
|
78
|
+
:target: https://pypi.python.org/pypi/pytest-codeblock
|
|
79
|
+
:alt: PyPI Version
|
|
80
|
+
|
|
81
|
+
.. image:: https://img.shields.io/pypi/pyversions/pytest-codeblock.svg
|
|
82
|
+
:target: https://pypi.python.org/pypi/pytest-codeblock/
|
|
83
|
+
:alt: Supported Python versions
|
|
84
|
+
|
|
85
|
+
.. image:: https://github.com/barseghyanartur/pytest-codeblock/actions/workflows/test.yml/badge.svg?branch=main
|
|
86
|
+
:target: https://github.com/barseghyanartur/pytest-codeblock/actions
|
|
87
|
+
:alt: Build Status
|
|
88
|
+
|
|
89
|
+
.. image:: https://readthedocs.org/projects/pytest-codeblock/badge/?version=latest
|
|
90
|
+
:target: http://pytest-codeblock.readthedocs.io
|
|
91
|
+
:alt: Documentation Status
|
|
92
|
+
|
|
93
|
+
.. image:: https://img.shields.io/badge/license-MIT-blue.svg
|
|
94
|
+
:target: https://github.com/barseghyanartur/pytest-codeblock/#License
|
|
95
|
+
:alt: MIT
|
|
96
|
+
|
|
97
|
+
.. image:: https://coveralls.io/repos/github/barseghyanartur/pytest-codeblock/badge.svg?branch=main&service=github
|
|
98
|
+
:target: https://coveralls.io/github/barseghyanartur/pytest-codeblock?branch=main
|
|
99
|
+
:alt: Coverage
|
|
100
|
+
|
|
101
|
+
`pytest-codeblock`_ is a `Pytest`_ plugin that discovers Python code examples
|
|
102
|
+
in your `reStructuredText`_ and `Markdown`_ documentation files and runs them
|
|
103
|
+
as part of your test suite. This ensures your docs stay correct and up-to-date.
|
|
104
|
+
|
|
105
|
+
Features
|
|
106
|
+
========
|
|
107
|
+
|
|
108
|
+
- **Markdown and reST support**: Automatically finds fenced code blocks
|
|
109
|
+
in `.md`/`.markdown` files and `.. code-block:: python` or literal blocks
|
|
110
|
+
in `.rst` files.
|
|
111
|
+
- **Grouping by name**: Split a single example across multiple code blocks;
|
|
112
|
+
the plugin concatenates them into one test.
|
|
113
|
+
- **Minimal dependencies**: Only requires `pytest`_.
|
|
114
|
+
|
|
115
|
+
Prerequisites
|
|
116
|
+
=============
|
|
117
|
+
Python 3.10+
|
|
118
|
+
|
|
119
|
+
Documentation
|
|
120
|
+
=============
|
|
121
|
+
- Documentation is available on `Read the Docs`_.
|
|
122
|
+
|
|
123
|
+
Installation
|
|
124
|
+
============
|
|
125
|
+
|
|
126
|
+
Install with `pip`_:
|
|
127
|
+
|
|
128
|
+
.. code-block:: sh
|
|
129
|
+
|
|
130
|
+
pip install pytest-codeblock
|
|
131
|
+
|
|
132
|
+
Or install with `uv`_:
|
|
133
|
+
|
|
134
|
+
.. code-block:: sh
|
|
135
|
+
|
|
136
|
+
uv pip install pytest-codeblock
|
|
137
|
+
|
|
138
|
+
Configuration
|
|
139
|
+
=============
|
|
140
|
+
*Filename: pyproject.toml*
|
|
141
|
+
|
|
142
|
+
.. code-block:: text
|
|
143
|
+
|
|
144
|
+
[tool.pytest.ini_options]
|
|
145
|
+
testpaths = [
|
|
146
|
+
"*.rst",
|
|
147
|
+
"**/*.rst",
|
|
148
|
+
"*.md",
|
|
149
|
+
"**/*.md",
|
|
150
|
+
]
|
|
151
|
+
|
|
152
|
+
Usage
|
|
153
|
+
=====
|
|
154
|
+
reStructruredText usage
|
|
155
|
+
-----------------------
|
|
156
|
+
Any code directive, such as ``.. code-block:: python``, ``.. code:: python``,
|
|
157
|
+
or literal blocks with a preceding ``.. codeblock-name: <name>``, will be
|
|
158
|
+
collected and executed automatically, if your `pytest`_ `configuration`_
|
|
159
|
+
allows that.
|
|
160
|
+
|
|
161
|
+
**Basic example**
|
|
162
|
+
|
|
163
|
+
.. code-block:: rst
|
|
164
|
+
|
|
165
|
+
.. code-block:: python
|
|
166
|
+
:name: test_basic_example
|
|
167
|
+
|
|
168
|
+
import math
|
|
169
|
+
|
|
170
|
+
result = math.pow(3, 2)
|
|
171
|
+
assert result == 9
|
|
172
|
+
|
|
173
|
+
You can also use a literal block with a preceding name comment:
|
|
174
|
+
|
|
175
|
+
.. code-block:: rst
|
|
176
|
+
|
|
177
|
+
.. codeblock-name: test_grouping_example_literal_block
|
|
178
|
+
This is a literal block::
|
|
179
|
+
|
|
180
|
+
y = 5
|
|
181
|
+
print(y * 2)
|
|
182
|
+
|
|
183
|
+
**Grouping example**
|
|
184
|
+
|
|
185
|
+
It's possible to split one logical test into multiple blocks.
|
|
186
|
+
They will be tested under the first ``:name:`` specified.
|
|
187
|
+
Note the ``.. continue::`` directive.
|
|
188
|
+
|
|
189
|
+
.. code-block:: rst
|
|
190
|
+
|
|
191
|
+
.. code-block:: python
|
|
192
|
+
:name: test_grouping_example
|
|
193
|
+
|
|
194
|
+
x = 1
|
|
195
|
+
|
|
196
|
+
Some intervening text.
|
|
197
|
+
|
|
198
|
+
.. continue: test_grouping_example
|
|
199
|
+
.. code-block:: python
|
|
200
|
+
:name: test_grouping_example_part_2
|
|
201
|
+
|
|
202
|
+
y = x + 1 # Uses x from the first snippet
|
|
203
|
+
assert y == 2
|
|
204
|
+
|
|
205
|
+
Some intervening text.
|
|
206
|
+
|
|
207
|
+
.. continue: test_grouping_example
|
|
208
|
+
.. code-block:: python
|
|
209
|
+
:name: test_grouping_example_part_3
|
|
210
|
+
|
|
211
|
+
print(y) # Uses y from the previous snippet
|
|
212
|
+
|
|
213
|
+
The above mentioned three snippets will run as a single test.
|
|
214
|
+
|
|
215
|
+
**pytest marks**
|
|
216
|
+
|
|
217
|
+
.. code-block:: rst
|
|
218
|
+
|
|
219
|
+
.. pytestmark: django_db
|
|
220
|
+
.. code-block:: python
|
|
221
|
+
:name: test_django
|
|
222
|
+
|
|
223
|
+
from django.contrib.auth.models import User
|
|
224
|
+
|
|
225
|
+
user = User.objects.first()
|
|
226
|
+
|
|
227
|
+
Markdown usage
|
|
228
|
+
--------------
|
|
229
|
+
|
|
230
|
+
Any fenced code block with a recognized Python language tag (e.g., ``python``,
|
|
231
|
+
``py``) will be collected and executed automatically, if your `pytest`_
|
|
232
|
+
`configuration`_ allows that.
|
|
233
|
+
|
|
234
|
+
**Basic example**
|
|
235
|
+
|
|
236
|
+
.. code-block:: markdown
|
|
237
|
+
|
|
238
|
+
```python name=test_basic_example
|
|
239
|
+
import math
|
|
240
|
+
|
|
241
|
+
result = math.pow(3, 2)
|
|
242
|
+
assert result == 9
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**Grouping example**
|
|
246
|
+
|
|
247
|
+
.. code-block:: markdown
|
|
248
|
+
|
|
249
|
+
```python name=test_grouping_example
|
|
250
|
+
x = 1
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Some intervening text.
|
|
254
|
+
|
|
255
|
+
```python name=test_grouping_example
|
|
256
|
+
print(x + 1) # Uses x from the first snippet
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**pytest marks**
|
|
260
|
+
|
|
261
|
+
.. code-block:: markdown
|
|
262
|
+
|
|
263
|
+
<!-- pytestmark: django_db -->
|
|
264
|
+
```python name=test_django
|
|
265
|
+
from django.contrib.auth.models import User
|
|
266
|
+
|
|
267
|
+
user = User.objects.first()
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Tests
|
|
271
|
+
=====
|
|
272
|
+
|
|
273
|
+
Run the tests with `pytest`_:
|
|
274
|
+
|
|
275
|
+
.. code-block:: sh
|
|
276
|
+
|
|
277
|
+
pytest
|
|
278
|
+
|
|
279
|
+
Writing documentation
|
|
280
|
+
=====================
|
|
281
|
+
|
|
282
|
+
Keep the following hierarchy.
|
|
283
|
+
|
|
284
|
+
.. code-block:: text
|
|
285
|
+
|
|
286
|
+
=====
|
|
287
|
+
title
|
|
288
|
+
=====
|
|
289
|
+
|
|
290
|
+
header
|
|
291
|
+
======
|
|
292
|
+
|
|
293
|
+
sub-header
|
|
294
|
+
----------
|
|
295
|
+
|
|
296
|
+
sub-sub-header
|
|
297
|
+
~~~~~~~~~~~~~~
|
|
298
|
+
|
|
299
|
+
sub-sub-sub-header
|
|
300
|
+
^^^^^^^^^^^^^^^^^^
|
|
301
|
+
|
|
302
|
+
sub-sub-sub-sub-header
|
|
303
|
+
++++++++++++++++++++++
|
|
304
|
+
|
|
305
|
+
sub-sub-sub-sub-sub-header
|
|
306
|
+
**************************
|
|
307
|
+
|
|
308
|
+
License
|
|
309
|
+
=======
|
|
310
|
+
|
|
311
|
+
MIT
|
|
312
|
+
|
|
313
|
+
Support
|
|
314
|
+
=======
|
|
315
|
+
For security issues contact me at the e-mail given in the `Author`_ section.
|
|
316
|
+
|
|
317
|
+
For overall issues, go
|
|
318
|
+
to `GitHub <https://github.com/barseghyanartur/pytest-codeblock/issues>`_.
|
|
319
|
+
|
|
320
|
+
Author
|
|
321
|
+
======
|
|
322
|
+
|
|
323
|
+
Artur Barseghyan <artur.barseghyan@gmail.com>
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
================
|
|
2
|
+
pytest-codeblock
|
|
3
|
+
================
|
|
4
|
+
|
|
5
|
+
.. External references
|
|
6
|
+
.. _reStructuredText: https://docutils.sourceforge.io/rst.html
|
|
7
|
+
.. _Markdown: https://daringfireball.net/projects/markdown/
|
|
8
|
+
.. _pytest: https://docs.pytest.org
|
|
9
|
+
.. _Django: https://www.djangoproject.com
|
|
10
|
+
.. _pip: https://pypi.org/project/pip/
|
|
11
|
+
.. _uv: https://pypi.org/project/uv/
|
|
12
|
+
|
|
13
|
+
.. Internal references
|
|
14
|
+
|
|
15
|
+
.. _pytest-codeblock: https://github.com/barseghyanartur/pytest-codeblock/
|
|
16
|
+
.. _Read the Docs: http://pytest-codeblock.readthedocs.io/
|
|
17
|
+
.. _Examples: https://github.com/barseghyanartur/pytest-codeblock/tree/main/examples
|
|
18
|
+
.. _Contributor guidelines: https://pytest-codeblock.readthedocs.io/en/latest/contributor_guidelines.html
|
|
19
|
+
|
|
20
|
+
Test your code blocks.
|
|
21
|
+
|
|
22
|
+
.. image:: https://img.shields.io/pypi/v/pytest-codeblock.svg
|
|
23
|
+
:target: https://pypi.python.org/pypi/pytest-codeblock
|
|
24
|
+
:alt: PyPI Version
|
|
25
|
+
|
|
26
|
+
.. image:: https://img.shields.io/pypi/pyversions/pytest-codeblock.svg
|
|
27
|
+
:target: https://pypi.python.org/pypi/pytest-codeblock/
|
|
28
|
+
:alt: Supported Python versions
|
|
29
|
+
|
|
30
|
+
.. image:: https://github.com/barseghyanartur/pytest-codeblock/actions/workflows/test.yml/badge.svg?branch=main
|
|
31
|
+
:target: https://github.com/barseghyanartur/pytest-codeblock/actions
|
|
32
|
+
:alt: Build Status
|
|
33
|
+
|
|
34
|
+
.. image:: https://readthedocs.org/projects/pytest-codeblock/badge/?version=latest
|
|
35
|
+
:target: http://pytest-codeblock.readthedocs.io
|
|
36
|
+
:alt: Documentation Status
|
|
37
|
+
|
|
38
|
+
.. image:: https://img.shields.io/badge/license-MIT-blue.svg
|
|
39
|
+
:target: https://github.com/barseghyanartur/pytest-codeblock/#License
|
|
40
|
+
:alt: MIT
|
|
41
|
+
|
|
42
|
+
.. image:: https://coveralls.io/repos/github/barseghyanartur/pytest-codeblock/badge.svg?branch=main&service=github
|
|
43
|
+
:target: https://coveralls.io/github/barseghyanartur/pytest-codeblock?branch=main
|
|
44
|
+
:alt: Coverage
|
|
45
|
+
|
|
46
|
+
`pytest-codeblock`_ is a `Pytest`_ plugin that discovers Python code examples
|
|
47
|
+
in your `reStructuredText`_ and `Markdown`_ documentation files and runs them
|
|
48
|
+
as part of your test suite. This ensures your docs stay correct and up-to-date.
|
|
49
|
+
|
|
50
|
+
Features
|
|
51
|
+
========
|
|
52
|
+
|
|
53
|
+
- **Markdown and reST support**: Automatically finds fenced code blocks
|
|
54
|
+
in `.md`/`.markdown` files and `.. code-block:: python` or literal blocks
|
|
55
|
+
in `.rst` files.
|
|
56
|
+
- **Grouping by name**: Split a single example across multiple code blocks;
|
|
57
|
+
the plugin concatenates them into one test.
|
|
58
|
+
- **Minimal dependencies**: Only requires `pytest`_.
|
|
59
|
+
|
|
60
|
+
Prerequisites
|
|
61
|
+
=============
|
|
62
|
+
Python 3.10+
|
|
63
|
+
|
|
64
|
+
Documentation
|
|
65
|
+
=============
|
|
66
|
+
- Documentation is available on `Read the Docs`_.
|
|
67
|
+
|
|
68
|
+
Installation
|
|
69
|
+
============
|
|
70
|
+
|
|
71
|
+
Install with `pip`_:
|
|
72
|
+
|
|
73
|
+
.. code-block:: sh
|
|
74
|
+
|
|
75
|
+
pip install pytest-codeblock
|
|
76
|
+
|
|
77
|
+
Or install with `uv`_:
|
|
78
|
+
|
|
79
|
+
.. code-block:: sh
|
|
80
|
+
|
|
81
|
+
uv pip install pytest-codeblock
|
|
82
|
+
|
|
83
|
+
Configuration
|
|
84
|
+
=============
|
|
85
|
+
*Filename: pyproject.toml*
|
|
86
|
+
|
|
87
|
+
.. code-block:: text
|
|
88
|
+
|
|
89
|
+
[tool.pytest.ini_options]
|
|
90
|
+
testpaths = [
|
|
91
|
+
"*.rst",
|
|
92
|
+
"**/*.rst",
|
|
93
|
+
"*.md",
|
|
94
|
+
"**/*.md",
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
Usage
|
|
98
|
+
=====
|
|
99
|
+
reStructruredText usage
|
|
100
|
+
-----------------------
|
|
101
|
+
Any code directive, such as ``.. code-block:: python``, ``.. code:: python``,
|
|
102
|
+
or literal blocks with a preceding ``.. codeblock-name: <name>``, will be
|
|
103
|
+
collected and executed automatically, if your `pytest`_ `configuration`_
|
|
104
|
+
allows that.
|
|
105
|
+
|
|
106
|
+
**Basic example**
|
|
107
|
+
|
|
108
|
+
.. code-block:: rst
|
|
109
|
+
|
|
110
|
+
.. code-block:: python
|
|
111
|
+
:name: test_basic_example
|
|
112
|
+
|
|
113
|
+
import math
|
|
114
|
+
|
|
115
|
+
result = math.pow(3, 2)
|
|
116
|
+
assert result == 9
|
|
117
|
+
|
|
118
|
+
You can also use a literal block with a preceding name comment:
|
|
119
|
+
|
|
120
|
+
.. code-block:: rst
|
|
121
|
+
|
|
122
|
+
.. codeblock-name: test_grouping_example_literal_block
|
|
123
|
+
This is a literal block::
|
|
124
|
+
|
|
125
|
+
y = 5
|
|
126
|
+
print(y * 2)
|
|
127
|
+
|
|
128
|
+
**Grouping example**
|
|
129
|
+
|
|
130
|
+
It's possible to split one logical test into multiple blocks.
|
|
131
|
+
They will be tested under the first ``:name:`` specified.
|
|
132
|
+
Note the ``.. continue::`` directive.
|
|
133
|
+
|
|
134
|
+
.. code-block:: rst
|
|
135
|
+
|
|
136
|
+
.. code-block:: python
|
|
137
|
+
:name: test_grouping_example
|
|
138
|
+
|
|
139
|
+
x = 1
|
|
140
|
+
|
|
141
|
+
Some intervening text.
|
|
142
|
+
|
|
143
|
+
.. continue: test_grouping_example
|
|
144
|
+
.. code-block:: python
|
|
145
|
+
:name: test_grouping_example_part_2
|
|
146
|
+
|
|
147
|
+
y = x + 1 # Uses x from the first snippet
|
|
148
|
+
assert y == 2
|
|
149
|
+
|
|
150
|
+
Some intervening text.
|
|
151
|
+
|
|
152
|
+
.. continue: test_grouping_example
|
|
153
|
+
.. code-block:: python
|
|
154
|
+
:name: test_grouping_example_part_3
|
|
155
|
+
|
|
156
|
+
print(y) # Uses y from the previous snippet
|
|
157
|
+
|
|
158
|
+
The above mentioned three snippets will run as a single test.
|
|
159
|
+
|
|
160
|
+
**pytest marks**
|
|
161
|
+
|
|
162
|
+
.. code-block:: rst
|
|
163
|
+
|
|
164
|
+
.. pytestmark: django_db
|
|
165
|
+
.. code-block:: python
|
|
166
|
+
:name: test_django
|
|
167
|
+
|
|
168
|
+
from django.contrib.auth.models import User
|
|
169
|
+
|
|
170
|
+
user = User.objects.first()
|
|
171
|
+
|
|
172
|
+
Markdown usage
|
|
173
|
+
--------------
|
|
174
|
+
|
|
175
|
+
Any fenced code block with a recognized Python language tag (e.g., ``python``,
|
|
176
|
+
``py``) will be collected and executed automatically, if your `pytest`_
|
|
177
|
+
`configuration`_ allows that.
|
|
178
|
+
|
|
179
|
+
**Basic example**
|
|
180
|
+
|
|
181
|
+
.. code-block:: markdown
|
|
182
|
+
|
|
183
|
+
```python name=test_basic_example
|
|
184
|
+
import math
|
|
185
|
+
|
|
186
|
+
result = math.pow(3, 2)
|
|
187
|
+
assert result == 9
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Grouping example**
|
|
191
|
+
|
|
192
|
+
.. code-block:: markdown
|
|
193
|
+
|
|
194
|
+
```python name=test_grouping_example
|
|
195
|
+
x = 1
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Some intervening text.
|
|
199
|
+
|
|
200
|
+
```python name=test_grouping_example
|
|
201
|
+
print(x + 1) # Uses x from the first snippet
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**pytest marks**
|
|
205
|
+
|
|
206
|
+
.. code-block:: markdown
|
|
207
|
+
|
|
208
|
+
<!-- pytestmark: django_db -->
|
|
209
|
+
```python name=test_django
|
|
210
|
+
from django.contrib.auth.models import User
|
|
211
|
+
|
|
212
|
+
user = User.objects.first()
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Tests
|
|
216
|
+
=====
|
|
217
|
+
|
|
218
|
+
Run the tests with `pytest`_:
|
|
219
|
+
|
|
220
|
+
.. code-block:: sh
|
|
221
|
+
|
|
222
|
+
pytest
|
|
223
|
+
|
|
224
|
+
Writing documentation
|
|
225
|
+
=====================
|
|
226
|
+
|
|
227
|
+
Keep the following hierarchy.
|
|
228
|
+
|
|
229
|
+
.. code-block:: text
|
|
230
|
+
|
|
231
|
+
=====
|
|
232
|
+
title
|
|
233
|
+
=====
|
|
234
|
+
|
|
235
|
+
header
|
|
236
|
+
======
|
|
237
|
+
|
|
238
|
+
sub-header
|
|
239
|
+
----------
|
|
240
|
+
|
|
241
|
+
sub-sub-header
|
|
242
|
+
~~~~~~~~~~~~~~
|
|
243
|
+
|
|
244
|
+
sub-sub-sub-header
|
|
245
|
+
^^^^^^^^^^^^^^^^^^
|
|
246
|
+
|
|
247
|
+
sub-sub-sub-sub-header
|
|
248
|
+
++++++++++++++++++++++
|
|
249
|
+
|
|
250
|
+
sub-sub-sub-sub-sub-header
|
|
251
|
+
**************************
|
|
252
|
+
|
|
253
|
+
License
|
|
254
|
+
=======
|
|
255
|
+
|
|
256
|
+
MIT
|
|
257
|
+
|
|
258
|
+
Support
|
|
259
|
+
=======
|
|
260
|
+
For security issues contact me at the e-mail given in the `Author`_ section.
|
|
261
|
+
|
|
262
|
+
For overall issues, go
|
|
263
|
+
to `GitHub <https://github.com/barseghyanartur/pytest-codeblock/issues>`_.
|
|
264
|
+
|
|
265
|
+
Author
|
|
266
|
+
======
|
|
267
|
+
|
|
268
|
+
Artur Barseghyan <artur.barseghyan@gmail.com>
|