python - 从 Nose 获取已使用的配置文件列表

标签 python nose nosetests

从使用nose运行测试的代码中,如何检索已在命令行上传递的配置文件列表(无需自己解析参数,因为nose应该在某处公开这些值),如下所示,

nosetests -c default.ini -c staging.ini

这将导致,

[default.ini, staging.ini]

我似乎无法在nose.config对象上找到这些值。

最佳答案

您的问题似乎是您对配置文件的命名与默认 Nose 配置文件的命名不同。

来自nose.config

config_files = [
    # Linux users will prefer this
    "~/.noserc",
    # Windows users will prefer this
    "~/nose.cfg"
    ]

def user_config_files():
    """Return path to any existing user config files
    """
    return filter(os.path.exists,
                  map(os.path.expanduser, config_files))


def all_config_files():
    """Return path to any existing user config files, plus any setup.cfg
    in the current working directory.
    """
    user = user_config_files()
    if os.path.exists('setup.cfg'):
        return user + ['setup.cfg']
    return user

缺点是,nose 正在寻找名为 ~/.noserc 或 ~/nose.cfg 的默认配置文件。如果它们没有像这样命名, Nose 将不会拾取它们,您将必须手动指定配置文件的名称,就像您在命令行上所做的那样

现在假设您有一些对象config,它是nose.config.Config实例,那么获得的最佳方法你的配置文件名是这样的

>>> from nose.config import Config
>>> c = Config()
>>> c.configure(argv=["nosetests", "-c", "foo.txt"])
>>> c.options.files
['foo.txt']

关于python - 从 Nose 获取已使用的配置文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17879282/

相关文章:

python - 关闭 Nose 测试中的覆盖范围

Python的nosetests运行测试两次

Python 抓取加密比较

python - 什么时候发电机不是发电机?为什么有时用 yield 调用我的函数不返回生成器对象

python - 使用Nose测试txmongo依赖代码

python - 列出 Nosetest 找到的所有测试

Python nose 关键测试与非关键测试

python - nosetest输出中字符 `S`代表什么

python - Sympy 符号矩阵指数

python - 将列表元素传递给 for 循环