1

我想让 scons 用目录列表调用nosetests。最好的方法是什么?

4

2 回答 2

3

如果您需要分析外部应用程序的返回码(例如,如果您调用测试),则需要使用 Command() + python subprocess 模块。如果您只使用命令,您将无法获得应用程序的返回码。

例如:

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

runTests 函数示例:

def runTests(target = None, source = None, env = None) :
    # fill args
    retCode = subprocess.call(args, env = env['ENV'], cwd = cwd, shell = True)
    Exit(retCode)

此外,您可以为 runTestsCmd 设置其他依赖项。

Depends(runTestsCmd, [appAndLibsToBuild])
于 2012-05-30T13:06:10.833 回答
1

我不知道鼻子框架,但是有两种方法可以使用 SCons 执行外部应用程序(还有其他方法可以使用 python,但无需提及)如下:

  • Execute () - 在分析 SConscript 文件时始终执行
  • Command () - 就像一个目标,只根据它的依赖执行

我认为您会希望使用 Command() 选项仅在相关依赖项之一发生更改时才启动单元测试。

关于目录列表,那么你可以使用一些 python 编程,像这样:

dirs = ['dir1', 'dir2', 'dir3']
for dir in dirs:
   cmd = 'theScriptToExecute $SOURCE $TARGET'
   env.Command(target = 'whatever', source = dir, action = cmd)
于 2012-05-30T12:39:02.900 回答