You can download this code by clicking the button below.
This code is now available for download.
This function defines a custom plugin class named RandomPlugin, inheriting from the nose Plugin class and implementing a custom random feature. The function configures a random option to make test cases have a random attribute.
Technology Stack : nose
Code Type : Custom function
Code Difficulty : Intermediate
def random_module_usage():
import random
from nose.plugins import Plugin
from nose.plugins.attrib import Attribute
class RandomPlugin(Plugin):
name = 'randomplugin'
def options(self, parser, env):
super(RandomPlugin, self).options(parser, env)
parser.add_option('--random-option', action='store_true', default=False,
help='enable random option')
def configure(self, options, conf):
super(RandomPlugin, self).configure(options, conf)
if getattr(options, 'random_option', False):
self.conf.addOption(Attribute('random'))
def make_argument_list(self, arglist, config):
arglist.extend(['--random-option'])
return RandomPlugin