[py-dev] Creating test skeleton automatically from modules

Edvard Majakari edvard.majakari at staselog.com
Tue Mar 15 14:07:25 MET 2005


Hi,

I wrote a simple program which uses Python's compiler module to parse given
set of modules and writes a py.test unit test skeleton for each
module. Currently it is not too clever, mostly because I don't have very clear
ideas how unit testing should be done. However, it does create code for
automatically generating test methods :)

Say, if you have module bar and therein method named foo, pytestgen will
automatically create 

TestBar:

  ...

  def test_foo(self):

      known_values(,)

      for arg1, arg2, expected in known_values:
          yield self.foo, arg1, arg2, expected

  def foo(self, arg1, arg2, expectd):
 
      assert bar.foo(arg1, arg2) == expected


I intend to develop the program further, hopefully integrate it to Eclipse
pydev plugin :)

If you're interested in trying it out, see

http://majakari.net/dl/pytestgen-0.11.tar.bz2

It's not too advanced (yet), but I already use it myself for my own purposes.

-- 
# Edvard Majakari		Software Engineer
# PGP PUBLIC KEY available    	Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";



More information about the py-dev mailing list