2013-07-26 5 views
1

nose를 사용하여 테스트를 실행하는 코드에서 nose가 이러한 값을 노출해야하므로 args를 직접 구문 분석하지 않고 명령 줄에서 전달 된 구성 파일 목록을 검색하는 방법 어딘가)를 초래Nose에서 사용 된 구성 파일 목록 가져 오기

nosetests -c default.ini -c staging.ini 

,

[default.ini, staging.ini] 

, 같이 나는 nose.config 개체에서이 값을 찾을 수 없습니다.

+1

말을하는 것입니다 또는'nose.config.all_config_files()'? –

+0

나는 둘 다 비어있다. – sowa

답변

1

기본 코 구성 파일의 이름을 지정하는 것과 다른 방식으로 구성 파일의 이름을 지정하는 것 같습니다. 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 

이의 짧은에서

, 즉 코는 ~/.noserc 또는 ~/nose.cfg라는 이름의 기본 구성 파일을 찾고 있습니다. 그들이 코와 같이 이름이 지정되지 않은 경우이를 선택하지 않아야합니다. 을 직접 입력해야합니다.은 명령 줄에서 수행하는 것처럼 구성 파일의 이름을 지정합니다.

이제 예를 들어 다음 설정 파일 이름을 얻을 수있는 가장 좋은 방법 nose.config.Config예를입니다 오브젝트 설정는`) (당신이`nose.config.user_config_files를 시도

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