Package: markdown-pytest
markdown-pytestThemarkdown-pytestplugin is apytestplugin that allows you to run tests
directly from Markdown files.With this plugin, you can write your tests inside Markdown files, making it
easy to read, understand and maintain your documentation samples.
The tests are executed just like any other Pytest tests.Sample of markdown file content:<!-- name: test_assert_true -->```pythonassertTrue```Will be shown asassertTrueRestrictionsSince there is no way to add attributes to a block of code in markdown, this
module only runs those tests that are marked with a special comment.The general format of this comment is as follows: parts separated by semicolons
are a colon separated key-value pairs, the last semicolon is optional,
and parts not containing a colon bill be ignored.Example:<!-- key1: value1; key2: value2 -->Multiline example:<!-- 
    key1: value1; 
    key2: value2;
-->This comment should be placed right before the block of code, exactly upper
the backticks, for example:<!-- name: test_name -->
```python
```Thenamekey is required, and blocks that do not contain it will be ignored.Some Markdown parsers support two or three dashes around comments, this module
supports both variants. Thecaseparameter is optional and might be used for
subtests, see "Code split" section.Common parsing rulesThis module uses its own, very simple Markdown parser, which only supports code
block parsing. In general, the parsing behavior of a file follows the following
rules:Code without<!-- name: test_name -->comment will not be executed.Allowed two or three dashes in the comment symbolsFor example following line will be parsed identically:<!--  name: test_name -->
<!--- name: test_name --->
<!--  name: test_name --->
<!--- name: test_name -->Code blocks with same names will be merged in one code and executed onceThe optional comment parametercasewill execute the block as a subtest.Indented code blocks will be shifted left.For example:<!-- name: test_name -->```pythonassertTrue```Is the same of:<!-- name: test_name -->```pythonassertTrue```Code splitYou can split a test into multiple blocks with the same test name:Markdown:This block performs import:

<!-- name: test_example -->```pythonfromitertoolsimportchain````chain`usage example:

<!-- name: test_example -->```pythonassertlist(chain(range(2),range(2)))==[0,1,0,1]```Will be shown asThis block performs import:fromitertoolsimportchainchainusage example:assertlist(chain(range(2),range(2)))==[0,1,0,1]subtests supportOf course, you can break tests into subtests by simply addingcase: case_nameto the markdown comment.<!-- name: test_counter -->```pythonfromcollectionsimportCounter```<!-- 
    name: test_counter;
    case: initialize_counter
-->```pythoncounter=Counter()```<!-- 
    name: test_counter;
    case: assign_counter_value
-->```pythoncounter["foo"]+=1assertcounter["foo"]==1```Will be shown asfromcollectionsimportCountercounter=Counter()counter["foo"]+=1assertcounter["foo"]==1Fictional Code ExamplesCode without<!-- name: test_name -->comment will not be executed.```pythonfromuniverseimportantigravity,WrongPlanettry:antigravity()exceptWrongPlanet:print("You are on the wrong planet.")exit(1)```Will be shown asfromuniverseimportantigravity,WrongPlanettry:antigravity()exceptWrongPlanet:print("You are on the wrong planet.")exit(1)Usage exampleThis README.md file might be tested like this:$pytest-vREADME.md=======================testsessionstarts=======================plugins:subtests,markdown-pytest
collected3items

README.md::test_assert_truePASSED[33%]README.md::test_examplePASSED[66%]README.md::test_counterSUBPASS[100%]README.md::test_counterSUBPASS[100%]README.md::test_counterPASSED[100%]