Skip to content

Instantly share code, notes, and snippets.

@iafisher
Last active June 23, 2018 16:11
Show Gist options
  • Save iafisher/663c0a85b1e51f10ad7a9570159a1d5c to your computer and use it in GitHub Desktop.
Save iafisher/663c0a85b1e51f10ad7a9570159a1d5c to your computer and use it in GitHub Desktop.
A demo of a testing utility for the Python shell that automatically generates unit tests based on your interactive session
>>> import mylib, testhelper as th
>>> fibonacci = th.register(mylib.fibonacci)
>>> fib(12)
144
[testhelper] Is this the expected result (y[es]/n[o]/c[ancel])? y
>>> fib(-1)
Traceback (most recent call last):
...
ValueError
[testhelper] Is this the expected result (y[es]/n[o]/c[ancel])? y
>>> print(th.compile())
import unittest
import mylib
class MyTestCase(unittest.TestCase):
def test_all(self):
self.assertEqual(mylib.fib(12), 144)
with self.assertRaises(ValueError):
mylib.fib(-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment