Fecthing unit test cases in python automatically -


I like that I am using solidarity Python simple code:

  suite = unittest.TestSuite () Suite.addTest (unittest.defaultTestLoader.loadTestsFromTestCase (module1)) suite.addTest (unittest.defaultTestLoader.loadTestsFromTestCase (module2))  

I want my test suite Finds all the modules and all the unit test cases files that we have written? E.g.

There are 5 files,

1). F1.py

2). F2.py

3). F3.py

4). F4.py

5). F5.py

We do not know what file test file file is in. I need a way through which each file will be parsed and given the name of module for unit test cases only

Note: - I am using Python 2.6.6 so that it can not actually be used unittest.TestLoaded.discover ()

< / Div>

Consider using the tool, it is completely The unit-trial life varies, only you run it in the source folder root such as:

  & gt; Nosetests  

Then it automatically finds all test cases.

If you want to run all the instructions, then use it:

  & gt; ; If you only want to find a list of the program's settings, then  nose  provides some APIs (Unfortunately, as  Testloder. (). 

< p> UPDATE : I just (a library that is found intend es) which later backported connected features of previous versions of Python I'm down for archaeologists I'll keep the given code, but I think, unittest2 A better way.

import nose. Loader import nose. Suite import types find Def _iter_modules (test): 'constant modules of all trials. (Some double) items to test if Istens items (nose Suitkcontekssait): _iter_modules (items) for t: produce T Elif isinstance (item.context, types.ModuleType): yield object reference .__ Nam__ other: yield object. Kntekst .__ module__ def find_test_modules (basedir): '' 'Get a list of all modules Switch to include test

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -