Chinaunix首页 | 论坛 | 博客
  • 博客访问: 836218
  • 博文数量: 253
  • 博客积分: 6891
  • 博客等级: 准将
  • 技术积分: 2502
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-03 11:01
文章分类

全部博文(253)

文章存档

2016年(4)

2013年(3)

2012年(32)

2011年(184)

2010年(30)

分类: Python/Ruby

2011-06-15 13:55:38

Mark Pilgrim gives a short but very useful program to run all your tests automatically in . If your testfiles all end in "test.py", this program will import all the classes in these files, make a TestSuite out of the TestCases or TestSuites they contain, and start unittest with that TestSuite. I call this program 'TestRunner.py':
  1. """Regression testing framework
  2.    This module will search for scripts in the same directory named
  3.    XYZTest.py. Each such script should be a test suite that tests a
  4.    module through PyUnit. (As of Python 2.1, PyUnit is included in
  5.    the standard library as "unittest".) This script will aggregate all
  6.    found test suites into one big test suite and run them all at once.
  7.    """

  8.    import unittest

  9.    import sys, os, re, unittest

  10.    def regressionTest():
  11.    path = os.path.split(sys.argv[0])[0] or os.getcwd()
  12.    files = os.listdir(path)
  13.    test = re.compile("test.py$", re.IGNORECASE)
  14.    files = filter(test.search, files)
  15.    filenameToModuleName = lambda f: os.path.splitext(f)[0]
  16.    moduleNames = map(filenameToModuleName, files)
  17.    modules = map(__import__, moduleNames)
  18.    load = unittest.defaultTestLoader.loadTestsFromModule
  19.    return unittest.TestSuite(map(load, modules))

  20.    if __name__ == "__main__":
  21.       unittest.main(defaultTest="regressionTest")

阅读(715) | 评论(0) | 转发(0) |
0

上一篇:pyunittest 1

下一篇:python reduce , map, filter

给主人留下些什么吧!~~