import os import subprocess ###################################################################### # 需要测试覆盖率的文件或者目录 cover_list = [ 'src/sample/analyzer/unpacker/src/emulator.py', 'src/sample/analyzer/unpacker/src/emulator_manager.py', 'src/sample/analyzer/unpacker/src/unpacker_analyzer.py', 'src/sample/analyzer/bitvalue/src/confparser.py', 'src/sample/analyzer/bitvalue/src/trunk.py', ] # 测试用例所在的文件或者目录,如果测试文件没有以test开头,则必须制定文件名 ut_list = [ 'src/sample/analyzer/unpacker/ut', 'src/sample/analyzer/bitvalue/ut/ut_main.py' ] ###################################################################### PRODUCTION_HOME = os.environ.get("PRODUCTION_HOME", "../..") def get_command(): command = [ 'nosetests', '--with-cov', '--cover-erase', '--cov-report', 'html', '--cov-config', 'cover.config', ] for cover in cover_list: command.append('--cov') command.append(os.path.join(PRODUCTION_HOME, cover)) for ut in ut_list: command.append(os.path.join(PRODUCTION_HOME, ut)) return command if __name__ == '__main__': command = get_command() print command os.chdir(PRODUCTION_HOME) proc = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = proc.communicate() return_code = proc.poll() print output print error print return_code |