Spocktest
Spocktest is a Python tool that runs tests for code snippets defined in standard Python files and injects them into documentation. Think of it as doctest but the other way around.
Motivation
The primary motivation behind Spocktest is the poor debuggability of tests generated with sphinx-doctest. While the standard doctest module does a good job of running code snippets against expected output, I've had much less luck with debugging sphinx-doctest.
I am currently of the belief that example code should be injected into documentation instead of the documentation to serve as a place to keep any tests and this repo will serve both as an experiment and as a potentially useful tool for building well-tested Wikis for Python software.
Current status
Spocktest is in early stages of development. If used in production, it's recommended you always create a copy of the output documentation with --output flag to prevent any latent bugs from clobbering your documentation source files. Apart from that make sure to keep your documentation under VCS!
How it works
-
A snippet is defined as a portion of code in a unit test file between an ID portion and a comment that ends the snippet, e.g.
def test_snippet_1(self): a = 1 a += 1 # SNIPPET_END self.assertEqual(a, 2)
As you can see the ending tag is useful to focus the snippet on the relevant code and omit testing boilerplate.
-
A placeholder is defined as a pattern that will be substituted with a concrete snippet, e.g.
# Doc1 ```python # --Snippet--: 1 ```
-
The defaults are configured for Python but nearly all behavior is configurable with Regex patterns:
- By default all snippet tests should be named:
test_snippet_{{ID}}.- Can be overridden with
--patternflag.
- Can be overridden with
- By default
# SNIPPET_ENDis the default ending tag.- Can be overridden with
--endflag.
- Can be overridden with
- All patterns must be matched exactly e.g.
#SNIPPET_ENDwill not work! - By default placeholders are written as
# --Snippet--: {{ID}}.- Can be overridden with
--target-patternflag.
- Can be overridden with
- By default
.mdand.rstfiles are supported for substitution.- Can be overridden with
--doc-extsflag.
- Can be overridden with
- By default
.oyfiles are searched for snippets.- Can be overridden with
--code-extsflag.
- Can be overridden with
- By default the
{{ID}}value needs to match(\w+)regex pattern, i.e spaces are not supported, unless overridden.- Can be overridden with
--id-regex-ovdflag.
- Can be overridden with
- By default all snippet tests should be named:
Installation and Usage
- Run
pip install spocktest. - Run
spocktest <path to test folder> <path to docs folder> -o <path to output folder>.
As of now it's recommended to use the -o flag at all times but if you're brave you can try modifying your docs in-place. If you omit the -o flag the docs folder will be replaced with an interpolated version.
To fine-tune extra configuration options use spocktest --help.
Metadata
Release files for spocktest 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spocktest-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for spocktest-1.0.3-py3-none-any.whl |
Release files / spocktest-1.0.3-py3-none-any.whl
| Download URL | spocktest-1.0.3-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af852161399baf0c6c0fdddc42fa759e78b8e86734b094d95a3ec4d030f8c38e
|
|
BLAKE2b-256 checksum How to use checksums |
53ac9f4131c85bf340a7e468fb792f2dcb2acfcb0868bf71b0697571930eac82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1
|
Security for spocktest 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.