While it is a nice idea, i don't think this feature deserves its own syntax. Besides doctests, another way of achieving this in Python might be:

def sum(l):
# implementation of sum

def test_sum():
assert sum([]) == 0
assert sum([1, 2, 3]) == 6

which IMO is nice enough.

-- Markus

"Tarek Ziadé" <tarek@ziade.org> wrote:
Hey

I've read about Pyret on hackernews: http://www.pyret.org/

and found the 'where' statement very compeling. Functions can end with a where that contains small unit
tests.

From the documentation example:
fun sum(l):
  cases(List) l:
    | empty => 0
    | link(first, rest) => first + sum(rest)
  end
where:
  sum([]) is 0
  sum([1, 2, 3]) is 6
end
 
It's quite similar to the doctests ideas I guess - but not intended to be documentation like them.

I ended up disliking docttests because of this doc+test duality by the way: it often ends up as a
not so good documentation and not so good tests.

Anyways, having a dedicated keyword to append after a function some tests as part of the language
has benefits imho:

- the scope is reduced to the function - so it helps making 'real' isolated unit tests.
- we do have the unittest conventions, but here it make tests a first class citizen in the language.

Cheers
Tarek



Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas