0

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 Answers1

1

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"))'"""
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Thanks, it works like a charm! one more favor @barmar..If I want to add Document ID value in this string externally. How can do it? – shekharsabale Jul 08 '23 at 15:37
  • Document ID to be added in string externally. I tried with string added in question but its not working. giving error: *** MKS124814: Cannot show view information: Missing end ) before " – shekharsabale Jul 08 '23 at 15:41
  • Use an f-strying if you want to insert variables inside the string. The f-string can be triple-quoted, e.g. `f"""...{variable}..."""` – Barmar Jul 08 '23 at 16:04