python - 从 python 调用时出现段错误,但从命令行正常运行

标签 python bash googletest

我正在编写一个 python 脚本,用于持续集成和测试,将由 bitten 调用。我们的单元测试使用谷歌测试框架。每个软件组件都有一个运行配置和其他所需服务并运行 gtest 可执行文件的 bash 脚本。 python 脚本遍历存储库以查找 bash 脚本,并使用 os.popen() 命令调用每个脚本。

Python 脚本 (UnitTest.py)

#!/usr/bin/python

import os
import fnmatch
import sys
import subprocess

repository_location = '/home/actuv/workspace/eclipse/iccs/'
unit_test_script_name = 'RunUnitTests.sh'

def file_locator(repo, script_name):
    # Function for determining all unit test scripts
    test_location = []
    for root, dirnames, filenames in os.walk(repo):
        for filename in fnmatch.filter(filenames, script_name):
            test_location.append(os.path.join(root))
    return test_location

def run_tests(test_locations, script_name):
    # Runs test scripts located at each test location
    for tests in test_locations:
        cmd = 'cd ' + tests + ';./' + script_name
        print 'Running Unit Test at: ' + tests
        os.popen(cmd)

################    MAIN    ################
# Find Test Locations
script_locations = file_locator(repository_location, unit_test_script_name)

# Run tests located at each location
run_tests(script_locations)

# End of tests
sys.exit(0)

bash 脚本

#!/bin/sh

echo "Running unit tests..."

# update the LD_LIBRARY_PATH to include paths to our shared libraries

# start the test server

# Run the tests

# wait to allow all processes to end before terminating the server
sleep 10s

当我从终端窗口手动运行 bash 脚本时,它运行良好。当我让 python 脚本调用 bash 脚本时,我在 bash 脚本的 TestSingleClient 和 TestMultiClientLA 行上遇到段错误。

最佳答案

尝试替换

os.popen(cmd)

proc = subprocess.Popen('./scriptname', shell = True, 
                       cwd = tests)
proc.communicate()

关于python - 从 python 调用时出现段错误,但从命令行正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13021941/

相关文章:

python - 如何将 "convert"dequed 对象转换为 Python 中的字符串?

python - 为什么我的 for 循环(python)在 4 次迭代后会改变行为?

linux - 遍历目录以查找 pom.xml 文件

bash - ": > file"对比 "> file"

linux - 在匹配前删除换行符 - Linux

c++ - GMock 泄漏内存

python - Sphinx 文档中的条件输出

python - 如何在 Django Web 应用程序中渲染 Matplotlib 绘图?

performance - 与 googletest 和 Jenkins 比较/趋势测试数据

c++ - 如何在 Google 测试 (gtest) 中使用 fixture 成员值运行参数化测试?