Python unittest - testing multiple files with the same name -


i attempting test multiple functions same name , signature. (student assignment submissions.) setup looks this:

testcases/     __init__     testcase1.py     submission1/         func.py     submission2/         func.py     submission3/         func.py 

each func.py contains function named foo. test each occurrence of foo same test suite. standard unittest setup of

    import unittest     func import foo      class testfoo(unittest.testcase):          def test_empty(self):             self.asserttrue(foo(''))     ...  if __name__ == '__main__':     unittest.main() 

has (unsurprisingly) problems from func import foo line since func not in same folder, , cannot seem pick proper import dynamically.

it struck me take advantage of having extended base class , eliminate need import doing like:

    import unittest      class testfoo(unittest.testcase):          def __init__(self, foo):             self.foo = foo          def test_empty(self):             self.asserttrue(self.foo('')) 

and in test program instantiate testfoo object , pass function test:

tf = testfoo(foo) 

but haven't been able define , call test suite.

or there entirely different approach need?


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -