nosetests - 输出`all_config_files`和`user_config_files`

时间:2013-03-29 10:33:23

标签: python nose nosetests

我有以下目录结构:

main/
    |setup.cfg
    |foo.cfg
    |tests/
          |setup.cfg
          |foo.cfg
          |test_simple.py

并测试test_simple.py

from nose.tools import *
from nose.config import all_config_files, user_config_files

def test_singe():
    print 'all:', all_config_files()
    print 'user:', user_config_files()
    assert_true(False)

main/我运行nosetests tests/test_simple.py,我得到:

all: ['setup.cfg']
user: []

我认为all_config_filesuser_config_files将返回所有配置文件。但我只得到最高setup.cfg

根据docs

all_config_files()
    Return path to any existing user config files, plus any setup.cfg
    in the current working directory.

user_config_files()
    Return path to any existing user config files

我希望找到文件main/tests/*.cfg。有什么问题?

1 个答案:

答案 0 :(得分:1)

根据source codeuser_config_files将只返回用户主文件夹中的配置:

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))

all_config_files将从根目录(运行nosetests的地方)返回user_config_files + setup.cfg:

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

希望有所帮助。