简体   繁体   English

骗子在不同的子目录中运行py.test

[英]Scons running py.test in different subdirectories

We have a large repository containing several Python packages(*). 我们有一个包含几个Python软件包(*)的大型存储库。 I want scons to run py.test in each of the sub directories and not from the project root. 我希望scons在每个子目录中运行py.test ,而不是从项目根目录运行。 This is proving rather frustrating. 事实证明,这令人沮丧。 Currently, I have this action with all error checking removed: 目前,我已执行此操作,并删除了所有错误检查:

def runTests (target = None, source = None, env = None):
    cmd = which(env['TEST_RUNNER'])
    if cmd:
        retCode = True
        for path in env['TEST_DIR_LIST']:
            print 'Doing directory %s:' % (path)
            retCode = retCode and subprocess.call([cmd], cwd=path)
        env.Exit(retCode)

Which I call as in the SConstruct file: 我在SConstruct文件中这样称呼它:

runTestsCmd = env.Command('runTests', None, Action(runTests, "Running tests"))
AlwaysBuild(runTestsCmd)
Alias('test', runTestsCmd)

And in each SConscript file, I have this: 在每个SConscript文件中,我都有:

env.Append(TEST_DIR_LIST = ['PackageDirectory'])

What I get is that only one instance of py.test is run. 我得到的是仅运行py.test的一个实例。 I can see the "Doing directory X" messages but no run of py.test. 我可以看到“正在执行目录X”消息,但没有运行py.test。

Clearly, there is a need to not clone the environment in SConscript or if the env is cloned, making sure that the addition to TEST_DIR_LIST happens on original env. 显然,没有必要在SConscript中克隆环境,或者如果克隆了env,请确保在原始env上添加了TEST_DIR_LIST。

So, my questions are two fold: 因此,我的问题有两个:

  1. Is this a sensible way of doing what I want ? 这是做我想要的明智的方式吗?
  2. If it is, What am I doing wrong ? 如果是, 我在做什么错 If it is not, what should I be doing ? 如果不是, 我该怎么办?

(*) Yes, we are looking at changing this. (*) 是,我们正在考虑对此进行更改。 No, it will not happens soon enough so I do need the above. 不,它不会足够快地发生,所以我需要上面的内容。

The problem is the line: 问题是这一行:

retCode = retCode and subprocess.call([cmd], cwd=path)

subprocess.call returns 0 (which evaluates to False ) on success. subprocess.call将返回0(其值为False )。 You need to insert a not or maybe do a proper check like this: 您需要插入一个not或进行如下适当检查:

retcode = subprocess.call([cmd], cwd=path)
if retcode != 0:
     print ("failed ...")
     break  # or not break if you want to continue anyway

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM