Skip to content

Instantly share code, notes, and snippets.

@tsibley
Created May 5, 2025 17:27
Show Gist options
  • Save tsibley/f6ee7787431376a4d4cd4721abbd65f8 to your computer and use it in GitHub Desktop.
Save tsibley/f6ee7787431376a4d4cd4721abbd65f8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import doctest
import sys
try:
script = sys.argv[1]
except IndexError:
sys.stderr.write(f"error: no script given\n")
sys.stderr.write(f"usage: {sys.argv[0]} <script>\n")
sys.exit(1)
__name__ = f"<{script}>"
exec(open(script).read(), globals())
failed, total = doctest.testmod()
if failed:
sys.stderr.write(f"error: {failed:,} test{'s' if failed != 1 else ''} failed\n")
if not total:
sys.stderr.write(f"error: no tests found\n")
sys.exit(1 if failed or not total else 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment