For python nose test classes : What is the correct way to pass optional arguments -


i have created python class test_getfilesize use nose

relevant sections:

def __init__(self,mytestfile="./filetest",testsize=102400):     ''' constructor'''     print " running __init__", testsize,mytestfile     self.testsize=testsize     self.mytestfile = mytestfile 

and workhorse method:

@with_setup(setup, teardown) def test_getfilesize(self):      nose.tools import ok_, eq_,with_setup      import mp4      open(self.mytestfile,"rb") out:           filesize=mp4.getfilesize(out)           eq_(self.testsize,filesize,msg='passed test  size')           print "results ", filesize,self.testsize 

if run nosetest against file containing class, correctly tests class using default values , correct setup , teardown methods. problem when write class that, setup method never gets run.

what want able test different file sizes ( i.e. pass filesize value).

if there better way it, ears. prefer not via command line if possible.

thanks jim

you write test function (not part of class) test function generator, each yield returning new function run arguments generate test. work if had 500 different filenames/filesizes list wanted test against.

see here simple example/docs: http://nose.readthedocs.org/en/latest/writing_tests.html#test-generators

with test class, things bit trickier - since doesn't allow use generator method class methods. use metaclass return class suitable number of functions run test (one per case, example.) might beyond want do.

that being said, might find sufficient have single test method iterates on list of filenames/sizes , performs test on each one. work there less, results in single "test" output line collective set of tests.

you might reference question answer how 1 person did this:

nose, unittest.testcase , metaclass: auto-generated test_* methods not discovered


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -