Nosetest,包括不需要的父目录 [英] Nosetest including unwanted parent directories
问题描述
我正在尝试将鼻子测试限制为特定目录,但是在测试运行期间,它包括我所针对的dir的父目录,并且这样做会引发错误.
I'm trying to limit nosetests to a specific directory, however during the test run it's including the parent directories of the dir I'm targetting and in doing so throws errors.
以下是测试运行输出的关键要素:
Here's the key elements of output from the test run:
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
部分:
I'm using buildout
with pbp.recipe.noserunner
. Here's the relevant /projects/myproject/buildout.cfg
section:
[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
设置为defaults
参数之一,以帮助限制导入,但仍然没有乐趣.
I've also tried setting where=myproject/specs
as one of the defaults
parameters to help limit the import but still no joy.
关于我要去哪里的任何建议吗?
Any suggestions on where I'm going wrong?
我尝试--exclude
父目录,但没有任何乐趣.
I've tried to --exclude
the parent directories but no joy.
推荐答案
我想您期望的是以下行为.
I suppose that you are expecting the following behavior.
nose.importer: DEBUG: Add path /projects/myproject
nose.importer: DEBUG: insert /projects/myproject into sys.path
为什么不尝试使用--match
或--exclude
模式来限制测试集?
Why not try a --match
or an --exclude
pattern to restrict the tests set ?
尝试:
--exclude myproject/myproject
我检查了鼻子的源代码.importer:鼻子递归add_path规格的父母包. 我认为除非您创建特定的导入程序,否则您不能绕过此操作... 我不知道鼻子API是否可行.
I check the source code of nose.importer : nose recursivly add_path the parents packages of specs. I think that you cannot bypass this unless you create a specific importer... I do not not know if this is possible this the nose 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)
这篇关于Nosetest,包括不需要的父目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!