Python 是否可以在noses setup.cfg中设置环境变量

Python 是否可以在noses setup.cfg中设置环境变量,python,nose,nosetests,Python,Nose,Nosetests,我正在处理一个相当庞大的嵌入式python项目。目前,测试隐藏在make调用后面,该调用在工作站上设置PYTHONPATH和LD_LIBRARY_路径,以便完成测试。是否可以在nose配置中指定此选项,以便用户只需调用目录中的nosetests 否则,我是否应该在测试文件中包含一些锅炉板来操作所需的路径?nose当前没有任何能力从配置文件设置环境变量: def _configTuples(self, cfg, filename): config = [] if self._con

我正在处理一个相当庞大的嵌入式python项目。目前,测试隐藏在make调用后面,该调用在工作站上设置PYTHONPATH和LD_LIBRARY_路径,以便完成测试。是否可以在nose配置中指定此选项,以便用户只需调用目录中的nosetests


否则,我是否应该在测试文件中包含一些锅炉板来操作所需的路径?

nose当前没有任何能力从配置文件设置环境变量:

def _configTuples(self, cfg, filename):
    config = []
    if self._config_section in cfg.sections():
        for name, value in cfg.items(self._config_section):
            config.append((name, value, filename))
    return config

def _readFromFilenames(self, filenames):
    config = []
    for filename in filenames:
        cfg = ConfigParser.RawConfigParser()
        try:
            cfg.read(filename)
        except ConfigParser.Error, exc:
            raise ConfigError("Error reading config file %r: %s" %
                              (filename, str(exc)))
        config.extend(self._configTuples(cfg, filename))
    return config
从配置文件中指定的任何配置选项都将直接作为元组存储在列表中。事实上,如果您尝试传递一些nose不接受的值,那么它将抛出一个错误

def _applyConfigurationToValues(self, parser, config, values):
    for name, value, filename in config:
        if name in option_blacklist:
            continue
        try:
            self._processConfigValue(name, value, values, parser)
        except NoSuchOptionError, exc:
            self._file_error(
                "Error reading config file %r: "
                "no such option %r" % (filename, exc.name),
                name=name, filename=filename)
        except optparse.OptionValueError, exc:
            msg = str(exc).replace('--' + name, repr(name), 1)
            self._file_error("Error reading config file %r: "
                             "%s" % (filename, msg),
                             name=name, filename=filename)
看看你得到一个Nosuch Optionerror的部分

你有一个选择,我已经涉猎了一点;使用它,您可以在某种文件中指定测试配置选项,如果您的值无法识别,nose将不会抛出错误


或者您可以在测试中加入一些@setup@teardown方法。我会非常谨慎地添加任何类型的setupTests.sh脚本,因为这只会增加运行测试的额外复杂性。

进一步阅读,我似乎需要设置一个在测试之前运行的测试装置。然而,nose文档似乎没有任何明确的例子。创建一个runtests.sh文件来设置环境,然后调用
nosetests
@JoranBeasley:这就是我试图避免的。这主要是一件方便的事情,因为IDE似乎只适合直接运行鼻测试。如果你在操作PYTHONPATH,听起来你有比正确设置测试环境更大的问题