从使用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/