Skip to content

Commit

Permalink
allow test_docs to fail if any code block fails
Browse files Browse the repository at this point in the history
  • Loading branch information
seanshahkarami committed Jun 18, 2020
1 parent 83bcf2b commit be6ce33
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@
import re
import subprocess
import logging
import sys


def run_python_code_block(code):
return subprocess.check_output(['python3', '-s'], input=code.encode())


exitcode = 0

for path in Path('.').glob('**/*.md'):
text = path.read_text()
for code in re.findall('```python(.*?)```', text, re.S):
try:
print(f'running {path}')
run_python_code_block(code)
except Exception as exc:
exitcode = 1
logging.exception(
f'code block failed in {path}\n\n```python{code}```\n\n')

sys.exit(exitcode)

0 comments on commit be6ce33

Please sign in to comment.