top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

python - nose config

0 votes
22 views

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)

This is complex enough that I wonder if the above approach is correct.

posted Aug 15, 2013 by Deepak Dasgupta

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

Similar Questions

Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.
QUERY HOME
...