Auty自动化测试框架第一篇——生成执行列表

[本文出自天外归云的博客园]

在Auty的scripts文件夹中编写一个create_selection.py文件,用于在同级目录下针对同级目录scripts下的所有脚本生成一个selection.txt文件,其中包含所有同级目录scripts文件夹下可执行的python脚本:

代码如下:

# -*- coding: utf-8 -*-
import sys
import os

def create_selection():
    path = sys.path[0]
    selection = []
    for i in os.walk(os.path.join(path,'scripts')):
        for fileName in i[2:3][0]:
            filePath = os.path.join(i[0],fileName)
            if(check_if_python(filePath)):
                selection.append(filePath)
    return selection

def check_if_python(fileName):
    if fileName.endswith('.py'):
        return True

def create_selection_file(selection):
    filePath = os.path.join(sys.path[0],'all_scripts_selection.txt')
    theFile = open(filePath,'w')
    for scriptPath in selection:
        theFile.write(scriptPath+'\n')
    theFile.close()

if __name__ == '__main__':
    selection = create_selection()
    create_selection_file(selection)

执行这个脚本,就会生成所有可以执行的脚本文件列表。

 
posted @ 2016-09-28 17:46  天外归云  阅读(4370)  评论(0编辑  收藏  举报