编程语言
首页 > 编程语言> > python-Nosetest,包括不需要的父目录

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

我正在使用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 / specs设置为默认参数之一,以帮助限制导入,但仍然没有乐趣.

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

编辑:

我试图-排除父目录,但没有任何乐趣.

解决方法:

我想您期望出现以下行为.

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

为什么不尝试使用–match或–exclude模式来限制测试集?

尝试:

--exclude myproject/myproject

我检查了nasal.importer的源代码:鼻子递归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)

标签:python,nose
来源: https://codeday.me/bug/20191010/1887577.html