How to run testmanger from python script.

I am trying to run testmanger and collect all the result into python to generate excel file and report in python. but for some reason i can not run testmanger in python.
I am trying to join matlab instace. so Simulink and testmanger is already opened. if i run
sltest.testmanager.run
in matlab command line then i can run the test file. so would like to do same thing using python and the extract the result of all the testcases in python and do further processing.
Please help me to solve the issue and i am also open for new suggestions.
Thank you very much in advanced.
my python code is looking like this,
import matlab.engine
# Connect running matlab session
future = matlab.engine.connect_matlab(background=True)
eng = future.result(30)
with eng:
results = eng.get_failed_results() # calling matlab function
print(results)
my matlab function
function [results] = get_failed_results()
%% run testmanger and collect result of all the testcases
resultTestFile = sltest.testmanager.run
testFileResultArray = getTestFileResults(resultTestFile);
%% Get the test suite results
testSuiteResultArray = getTestSuiteResults(testFileResultArray);
%% Get the test case results
testCaseResultArray = getTestCaseResults(testSuiteResultArray);
testCaseResultArray
end

 Accepted Answer

my mistake was that i was not telling matlab to share the session, so
I ran following commnad in matlab
matlab.engine.shareEngine('Engine_1')
after that in python i ran following command to connect witht that share session
future = matlab.engine.connect_matlab(name='Engine_1', background=True)
eng = future.result(30)
# you can verify the name of session by following code
matlab_session = matlab.engine.find_matlab()[0]
print(matlab_session)

More Answers (0)

Products

Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!