I sometimes write small functions in an interactive shell.
They are rarely correct for the first time, so I spend a lot of time running versions of my function on the same set of tests to check the correctness.
>>> def test_foo():
print( foo(4) == 5 )
print( foo(8) == 9 )
>>> def foo(x): return x + 1
>>> test_foo()
True
True
But it foocan be more complicated, and I may need 5 or more rewrites to make it pass my tests, since running the package manually is boring, I need something like this:
>>> def test_foo():
print( foo(4) == 5 )
print( foo(8) == 9 )
>>> :SET_ON_EXECUTION test_foo
And now every time I rewrite my function fooand send it to the definition, the test will also run.
Some research
- A Google search does not provide any useful answer.
- The shell
python -hdoes not say how to do this. %quickref 'ipython, `.