It's all about the answers!

Ask a question

Run a python test script with RQM


mike jojo (11) | asked May 03, 4:30 p.m.

 i have a python script containing a function add(X1,X2) and return X1+x2.


i write a python test script (add_test.py) to which calls my function to test.

import pytest
import pythondemo


def test():
    value1 = 4.0
value2 = 4.0
    result = pythondemo.add(value1, value2) %%function to test
    assert result == 8.0

My goal is to run the script add_test.py through RQM through command line adapter and observe the behaviour like in pytest. 

i am able until now to do a connexion to RQM with command line adapter. 

My concern is to write the batch file which calls and executed my python test script (add_test.py) to pass through Command field, how do write such a batch file? i am not an expert. 

Which argument is passed through the argument field? In my case is it value1 and value2?

3 answers



permanent link
Subhajit Bhuiya (5992) | answered May 04, 1:19 a.m.
JAZZ DEVELOPER

 1st create a .bat file and use it to run the python script. Do it with out RQM.

To run the script using RQM, please check


Comments
mike jojo commented May 04, 5:14 a.m.

thanks for you reply,


i wrote this article before, but the contain of the batch file myTestTool.bat is not shown so that for someone like me who has no idea on how to write a batch file, can use it as input to see how it uses the python script to test. Also, the relationship between the Arguments arg1 arg2 arg3 and the myTestTool.bat is not clarified. Are they the input parameters to pass to the python function to test which seems to be called in myTestTool.bat?

mike


permanent link
Ralph Schoon (58.0k23642) | answered May 04, 2:50 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited May 04, 2:53 a.m.

 Writing a batch or shell script is no rocket science. I would suggest to search the internet for tutorials like https://www.tutorialspoint.com/batch_script/index.htm and do them.


The code below is an example I wrote based on the help and the article mentioned by Subhajit.

The first line just prints Test, the second prints all parameters passed. The rest of the lines create some files and links that are returned and hooked up to the test result.

You could put your call of the python script into the example below and play around with it.

echo Test
echo %*

set > c:\Temp\SetEnv.txt

echo SomeDocument=C:/shared/SomeDocument.txt >> %qm_AttachmentsFile%
echo SetEnv=c:/Temp/SetEnv.txt >> %qm_AttachmentsFile%
echo Jazz.net=https://jazz.net >> %qm_AttachmentsFile%
echo Google=https://google.com >> %qm_AttachmentsFile%

echo CustomAttributesFile is %qm_CustomAttributesFile% > c:\Temp\Files.txt
echo CustomPropertiesFile is %qm_CustomPropertiesFile% >> c:\Temp\Files.txt
echo ExecutionVariableFile is %qm_ExecutionVariablesFile% >> c:\Temp\Files.txt
echo AttachmentsFile is %qm_AttachmentsFile% >> c:\Temp\Files.txt
echo Files=c:/Temp/Files.txt >> %qm_AttachmentsFile%

permanent link
Pierre Bentkowski (61510) | answered May 05, 11:23 p.m.
You can call the python script directly without creating a DOS wrapper.

You can call is the same way you do on the command line:
    python c:\python-scripts arg1 arg2

Just make sure you exit with
SystemExit(int verdict)
    
To provide a verdict to to ETM

Your answer


Register or to post your answer.