im issue CLI command string works in cmd line not with Python sub process

87 Views Asked by At

Following im issue CLI command string works in cmd line not with Python sub process : CLI command working in Command Line:

im issues --queryDefinition='((field["Project"]="/L2H0090") and (field["Document ID"]="11601660") and (field["Status_fld"]="reviewed","released","approved") and (field["Category"]="Software Test") and (field["External ID"]contains"Fully_Automated"))'

Python Code:

import subprocess

string = "im issues --queryDefinition="+'((field["Project"]="/L2H0090") and (field["Document ID"]="11601660") and (field["Status_fld"]="reviewed","released","approved") and (field["Category"]="Software Test") and (field["External ID"]contains"Fully_Automated"))'
try:
    result = subprocess.check_output(string)
    print(result)
except subprocess.CalledProcessError as e:
    print(e.output)

Its showing below error: *** The query and queryDefinition options are incompatible with an issue selection.

I've tried way to input string to the subprocess.check_output. But every time same output I am getting. Please support here to get correct command string which shall work in python as well.

Thanks in advance.

string = """im issues --queryDefinition='((field["Project"]="/L2H0090") and (field["Document ID"])=""" + str(TestSuite_ID) + """ and (field["Status_fld"]="reviewed","released","approved") and (field["Category"]="Software Test") and (field["External ID"]contains"Fully_Automated")'"""

1

There are 1 best solutions below

3
Barmar On

The Python code is missing the ' around the value of the --queryDefinition option.

If you have a string that contains both single and double quotes, it's easiest to write it by delimiting it with triple quotes, rather than concatenating strings with different delimiters around each part. When you do the latter, it's easy to miss some of the nested quotes.

So copy the command you entered in the CLI, and just paste it inside a triple-quoted string.

string = """im issues --queryDefinition='((field["Project"]="/L2H0090") and (field["Document ID"]="11601660") and (field["Status_fld"]="reviewed","released","approved") and (field["Category"]="Software Test") and (field["External ID"]contains"Fully_Automated"))'"""