I'm trying to implement a set of nose tests running form within my python code.
I'm calling nose run
method from this file, adding it a custom plugin based on an example from the nose docs:
import os
import sys
import outer_packages
import nose
from nose.plugins import Plugin
import misc_methods
from rednose import RedNose
import termstyle
class CTRexScenario():
configuration = None
trex = None
platform = None
class CTRexTestConfiguringPlugin(Plugin):
def options(self, parser, env={}):
parser.add_option('--trex-scenario-config', action='store',
dest='config_path', default='config/config.yaml',
help='Specify path to the T-Rex testing scenario, defining T-Rex, platform and a TFTP server. Default is /config/config.yaml')
def configure(self, options, conf):
if options.config_path:
self.configuration = misc_methods.load_complete_config_file(options.config_path)
self.enabled = True
def begin (self):
CTRexScenario.configuration = self.configuration
def set_report_dir (report_dir):
if not os.path.exists(report_dir):
os.mkdir(report_dir)
if __name__ == "__main__":
# setting defaults. By default we run all the test suite
specific_tests = False;
long_test = False
report_dir = "reports"
for arg in sys.argv:
if 'unit_tests/' in arg:
specific_tests = True;
nose_argv= sys.argv + ['-s','-v','--exe', '--rednose', '--with-xunit','--xunit-file=' + report_dir + "/unit_test.xml"]
# Run all of the unit tests or just the selected ones
if not specific_tests:
nose_argv += ['unit_tests']
result = nose.run(argv = nose_argv, addplugins = [RedNose(), CTRexTestConfiguringPlugin()])#, plugins=[CConfiguringPlugin()])
if result == True:
print termstyle.green("passed!")
sys.exit(0)
else:
sys.exit(-1);
Now, I want do create a general test case, from which, containing this Scenario such that there will be a same shared scenario for all of the following tests. i.e.- All tests inheriting from the general case will base on the very same setUp
and tearDown
methods.
Here's the general test file:
from nose.plugins import Plugin
import trex
import misc_methods
import sys
class CTRexGeneral_Test():
"""This class defines the general testcase of the T-Rex traffic generator"""
def setUp(self):
self.a = CTRexScenario()
##### Here I want to config the rest of the scenario, based on the passed configuration file
def test_can_frobnicate(self):
assert (self.a.configuration==None)
# assert 2*5==10
def tearDown(self):
pass
Unfortunately, I don't understand how should I access the fetched configuration (which parsed already by the Plugin) from the general test file
Thanks!!