hi, I'm using nose to generate and run some tests not for python code, but for 
an html repository. I know this isn't the typical way to use nose, and so I'm 
asking here if the following code smells wrong.

I pass some args with the testconfig plugin and run a class setup method one 
time to get some information from a database. 
Then the tests get generated and run. During the run, a database is updated 
with the result. That is an intentional side-effect of running the test....is 
that okay or something that should never be done?

I've shortened the actual code to make it readable, but the main thing is the 
setup (setting class vars), the test generator, and the actual test (plus the 
database update):

class HtmlTester(object):
    '''
    Run this setup method once before tests begin.
    Reads from tconfig args to get document from database.
    '''
    @classmethod
    def setup_class(cls):
        name = tconfig['name']
        language = tconfig.get('language', 'en')
        report = db.conn({'name':name, 
                          'language':language, 
                          'format':'html})

    @attr('images')
    def test_images(self):
        for image in self.report['images']:
            yield (self.check_image, image)
    
    def check_image(self, image):
        '''
        True if image can be read, otherwise False
        '''
        r = False
        if get_imagesize(image):
            p = ImageFile.Parser()
            try:
                p.feed(open(image).read())
            except IOError:
                r = False
            else:
                r = True
       
        self.report.update({'image':image, 'result':r, 
                            'name': self.name, 
                            'language': self.language})
        assert_true(r)
  
 if __name__ == '__main__':
     args = sys.argv[:1] + ['--tc=name:mybook', 
                            '--tc=language:en' ] + sys.argv[1:]
    nose.run(argv=args)

I've used nose before in simpler situations, but not an expert.
This is complex enough that I wonder if the above approach is correct.

thanks,
--Tim
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to