2011-06-01 73 views
9

我试图限制nosetests到一个特定的目录,但是在测试运行期间它包括目标的目录的父目录,并在这样做会引发错误。Nosetest包括不需要的父目录

这里输出的关键要素,从试运行:

nose.importer: DEBUG: Add path /projects/myproject/myproject/specs 
nose.importer: DEBUG: Add path /projects/myproject/myproject 
nose.importer: DEBUG: Add path /projects/myproject 
nose.importer: DEBUG: insert /projects/myproject into sys.path 

我使用buildoutpbp.recipe.noserunner。以下是相关/projects/myproject/buildout.cfg部分:

[specs] 
recipe = pbp.recipe.noserunner 
eggs = 
    pbp.recipe.noserunner 
    ${buildout:eggs} 
    figleaf 
    pinocchio 
working-directory = 
    myproject/specs 
defaults = 
    -vvv 
    --exe 
    --include ^(it|ensure|must|should|specs?|examples?) 
    --include (specs?(.py)?|examples?(.py)?)$ 
    --with-spec 
    --spec-color 

我也试着设置where=myproject/specsdefaults参数之一,以帮助限制进口,但仍然没有喜悦。

关于我要去哪里的任何建议是错误的?

编辑:

我试图--exclude父目录,但没有喜悦。

回答

5

我想你会期待以下行为。

nose.importer: DEBUG: Add path /projects/myproject 
nose.importer: DEBUG: insert /projects/myproject into sys.path 

为什么不尝试--match--exclude模式限制设置测试?

尝试:

--exclude myproject/myproject 

我检查nose.importer的源代码:鼻子recursivly add_path规格的家长包。 我认为你不能绕过这个,除非你创建一个特定的导入器... 我不知道这是否可能这鼻子的API。

def add_path(path, config=None): 
    """Ensure that the path, or the root of the current package (if 
    path is in a package), is in sys.path. 
    """ 

    # FIXME add any src-looking dirs seen too... need to get config for that 

    log.debug('Add path %s' % path)  
    if not path: 
     return [] 
    added = [] 
    parent = os.path.dirname(path) 
    if (parent 
     and os.path.exists(os.path.join(path, '__init__.py'))): 
     added.extend(add_path(parent, config)) 
    elif not path in sys.path: 
     log.debug("insert %s into sys.path", path) 
     sys.path.insert(0, path) 
     added.append(path) 
    if config and config.srcDirs: 
     for dirname in config.srcDirs: 
      dirpath = os.path.join(path, dirname) 
      if os.path.isdir(dirpath): 
       sys.path.insert(0, dirpath) 
       added.append(dirpath) 
    return added 


def remove_path(path): 
    log.debug('Remove path %s' % path) 
    if path in sys.path: 
     sys.path.remove(path) 
+0

谢谢;我应该意识到最好的调查方法是阅读源代码! – 2011-06-10 07:56:00

+1

那么,确保你没有'__init __。py'(或'__init __。pyc'),它不是必需的,对吗? – Danimal 2015-07-28 11:06:58