pytest-codeblocks icon indicating copy to clipboard operation
pytest-codeblocks copied to clipboard

Suport for interactive Python shell code?

Open liqimai opened this issue 3 years ago • 2 comments

It is quite often markdown contains interactive Python shell code like:

>>> print("Hello World!")
Hello World!
>>> def add(a, b):
...     return a + b
...
>>> add(2,3)
5

Currently, I got following exception for these blocks in my README.md.

invalid syntax (<string>, line 1)

Can you add support to test it? I expect the behaviour to be same as pytest --doctest-modules, as if the code block is a function's doc-string.

liqimai avatar Mar 29 '22 22:03 liqimai

Interesting idea! I don't have any spare time to devote to this right now, but you can either submit a PR or sponsor me so I can move this into my working hours.

nschloe avatar Mar 29 '22 22:03 nschloe

I came here looking for this too, I just thought it worth mentioning that Github supports syntax highlighting of interactive codeblocks with a different code than normal Python, pycon, e.g.:

```pycon
 >>> "Hello " + "stranger"
 'Hello stranger'
```

Renders as:

>>> "Hello " + "stranger"
'Hello stranger'

antonagestam avatar Jun 06 '22 13:06 antonagestam