Python doctests embedded in README.md: "Expected: ``` Got nothing"

Viewed 258

I have a markdown file README.md containing the following code block at the start, and various other code blocks throughout:

```python
>>> import mypackage
```

I am trying to use doctest to verify that the code in README.md all runs correctly by calling

$ doctest README.md

which I expect to output something like

   docs: commands succeeded
   congratulations :)

since the tests are so simple. Instead, at the end of each block, I get an error message along the lines of

Failed example:
    import mypackage
Expected:
    ```
Got nothing

indicating to me that doctest is interpreting the closing backticks of my code block as expected output. I have temporarily resolved the issue by adding a newline before the closing backticks of each code block. I.e.

```python
>>> import mypackage

```

However, this feels kludgy and forces me to remember to add the newline to any new code blocks I add in the future.

Is there a right way to have doctest ignore the closing backticks of markdown code blocks?

0 Answers
Related