9

我试图将鼻子测试限制到特定目录,但是在测试运行期间它包括我要定位的目录的父目录,这样做会引发错误。

以下是测试运行输出的关键元素:

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

我正在buildout使用pbp.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父目录,但没有任何乐趣。

4

1 回答 1

5

我想你期待以下行为。

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

为什么不尝试一个--match或一个--exclude模式来限制测试集?

尝试:

--exclude myproject/myproject

我检查了nose.importer 的源代码:nose recursivly add_path the parents packages of specs。我认为除非你创建一个特定的导入器,否则你不能绕过这个......我不知道这是否可能是鼻子 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)
于 2011-06-07T12:09:20.320 回答