Testing 将python脚本作为独立脚本和测试运行

Testing 将python脚本作为独立脚本和测试运行,testing,scripting,config,combinations,nose,Testing,Scripting,Config,Combinations,Nose,我有python脚本,它们在CLI上与配置文件一起运行。测试脚本的所有内容都在类“ABC”内 在ABC类的init中,我传递脚本中使用的配置文件 因此,当我独立运行python脚本时,我会说“pythonscript_one.py-c config.cfg” 现在的问题是,我需要使用nosetest运行目录中的所有python测试。nose测试库不喜欢我在类ABC的init()中传递“config” 我需要一种运行python的方法,就像上面提到的那样,使用config和nosetests 我切

我有python脚本,它们在CLI上与配置文件一起运行。测试脚本的所有内容都在类“ABC”内

在ABC类的init中,我传递脚本中使用的配置文件

因此,当我独立运行python脚本时,我会说“pythonscript_one.py-c config.cfg”

现在的问题是,我需要使用nosetest运行目录中的所有python测试。nose测试库不喜欢我在类ABC的init()中传递“config”

我需要一种运行python的方法,就像上面提到的那样,使用config和nosetests

我切换到Python中的ConfigParser模块,它解析配置文件,我不必将它们传递给init()

正在main()中引用配置文件:

如果使用了config=c.parse_-config()test=TestMe(config),那么我必须将配置文件(xyz.cfg)作为“script_1.py-c xyz.cfg”)传递给TestMe类,有没有办法在鼻测试中利用它?我问这个问题,因为鼻测试不允许我将“config”传递给TestMe类的init()

当我执行“nosetests script_1.py”时,config.read(文件)导致一个错误


有没有一种方法可以让我的脚本在配置和nosetests中独立运行?

nose testconfig解决了所有问题!非常方便

class TestMe(object):
    def __init__(self):
        config = ConfigParser.ConfigParser()
        config.read(file)
if __name__ == '__main__':

    #config = c.parse_config()
    #test = TestMe(config)
    file = "configs/test_config.yaml"
    print "inside main..."
    config = ConfigParser.ConfigParser()
    config.read(file)
E
======================================================================
ERROR: Failure: TypeError ('type' object is not iterable)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/nose/loader.py", line 519, in makeTest
    return self._makeTest(obj, parent)
  File "/usr/local/lib/python2.7/site-packages/nose/loader.py", line 578, in _makeTest
    return MethodTestCase(obj)
  File "/usr/local/lib/python2.7/site-packages/nose/case.py", line 345, in __init__
    self.inst = self.cls()
  File "/home/..../script_1.py", line 30, in __init__
    config.read(file)
  File "/usr/local/lib/python2.7/ConfigParser.py", line 300, in read
    for filename in filenames:
TypeError: 'type' object is not iterable