首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Python在CANoe中运行测试模块

使用Python在CANoe中运行测试模块
EN

Stack Overflow用户
提问于 2020-05-25 11:30:13
回答 1查看 1.9K关注 0票数 1

我开发了一个基于Python的独木舟自动化代码,其中我启动了独木舟,打开配置并加载测试规范并运行它。

现在,我想等到Test执行完成后再注意判决结果。但不知道该怎么做。任何帮助都将不胜感激。

代码语言:javascript
复制
"""Execute XML Test Cases without a pass verdict"""
from time import sleep
import win32com.client as win32
import configparser
import time
from pandas.core.computation.expressions import set_test_mode
import pythoncom


testComplete = False

class TestModuleEvents(object):
    def OnReportGenerated(self,Success, SourceFullName, GeneratedFullName):
        print("Report Generated")
        testComplete = True
    def OnStop(self, value):
        print("Test Module Stopped")
        testComplete = True

    def OnStart(self):
        print("Test Module Started")
        testComplete = True

class TestConfigurationEvents(object):
    def OnStart(self):
        print("Measurement Started")
        testComplete = False

    def OnStop(self):
        print("Measurement Stopped")
        testComplete = True

config = configparser.RawConfigParser()
config.read('usecase02_configuration.properties')
configurationPath = config.get('TESTCONFIGURATION', 'configurationpath')
testspec = config.get('TESTCONFIGURATION', 'testspecification')

CANoe = win32.DispatchEx("CANoe.Application")
CANoe.Open(configurationPath)

testSetup = CANoe.Configuration.TestSetup
testSetup.TestEnvironments.Add(testspec)
test_env = testSetup.TestEnvironments.Item('Test Environment')
test_env = win32.CastTo(test_env, "ITestEnvironment2")


print(report.FullName)

# Get the XML TestModule (type <TSTestModule>) in the test setup
test_module = test_env.TestModules.Item('Tester')
CANoe.Measurement.Start()
sleep(5)   # Sleep because measurement start is not instantaneous

win32.WithEvents(test_module, TestModuleEvents)
test_module.Start()

# sleep(60)

while test_module.Verdict==0:
    time.sleep(1)

# test_module.Stop()
print(test_module.Verdict)
EN

回答 1

Stack Overflow用户

发布于 2020-05-28 06:18:30

你把所有零件都准备好了。我认为唯一的问题是对python中全局变量工作方式的误解。

在python文件的全局范围内声明testComplete。在TestModuleEvents.OnStop中,您可以声明另一个名为testComplete的变量。此实例与全局范围中的变量完全无关。

将您的OnStop-handler (以及其他部分)更改为如下所示:

代码语言:javascript
复制
    def OnStop(self, value):
        global testComplete
        print("Test Module Stopped")
        testComplete = True

这将将全局变量导入到您的作用域中,并将该变量设置为True,而不是创建新的变量。

完成此操作后,将while循环更改为:

代码语言:javascript
复制
while not testComplete:
    time.sleep(1)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62001525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档