Search code examples
pythonnosenosetests

nosetests - output of `all_config_files` and `user_config_files`


I have the following directory structure:

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

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

From main/ I run nosetests tests/test_simple.py and I get:

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

I thought either all_config_files or user_config_files will return all configuration files. But I get only the top setup.cfg.

According to the 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

I would expect files main/tests/*.cfg to be found. What is wrong?


Solution

  • According to the source code, user_config_files will just return configs from user's home folder:

    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 will return user_config_files + setup.cfg from the root dir (where you run nosetests):

    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
    

    Hope that helps.