When a markdown code block raises TypeError, pytest-markdown-docs runs the block a second time. The except TypeError fallback in MarkdownInlinePythonItem.runtest (plugin.py L122-L130, added in #62) is there to detect custom runners that don't accept the asyncio_runner kwarg, but it also catches a TypeError coming from the user's code and re-runs the whole block. Side effects happen twice, and combined with retry:N the block runs 2*(N+1) times.
Repro with pytest-markdown-docs 0.9.2, test_bug.md:
```python
with open("counter.txt", "a") as f:
f.write("ran\n")
raise TypeError("boom")
```
$ pytest --markdown-docs test_bug.md
$ wc -l counter.txt
2 counter.txt
Expected 1 line, the block should run once. The same block with retry:2 writes 6 lines instead of 3.
The test still fails with the right traceback either way, so this is invisible unless the block has side effects (file writes, network calls, counters in docs examples).
I have a fix ready that inspects the runner's runtest signature once instead of catching TypeError at call time, so custom runners without the kwarg keep working. Happy to open a PR.
When a markdown code block raises
TypeError, pytest-markdown-docs runs the block a second time. Theexcept TypeErrorfallback inMarkdownInlinePythonItem.runtest(plugin.py L122-L130, added in #62) is there to detect custom runners that don't accept theasyncio_runnerkwarg, but it also catches aTypeErrorcoming from the user's code and re-runs the whole block. Side effects happen twice, and combined withretry:Nthe block runs2*(N+1)times.Repro with pytest-markdown-docs 0.9.2,
test_bug.md:Expected 1 line, the block should run once. The same block with
retry:2writes 6 lines instead of 3.The test still fails with the right traceback either way, so this is invisible unless the block has side effects (file writes, network calls, counters in docs examples).
I have a fix ready that inspects the runner's
runtestsignature once instead of catchingTypeErrorat call time, so custom runners without the kwarg keep working. Happy to open a PR.