Ask a Question

Code Snippet operation with Python has syntax error when assigning variable value

SOLVED
tphillips
Frequent Contributor

Code Snippet operation with Python has syntax error when assigning variable value

Hi

 

I am have made a new TestComplete project and I have found that the Code Snippet keyword test step fails with a syntax error when a variable is being assigned to:

tphillips_0-1630540562607.png

 

tphillips_2-1630540601079.png

I have noticed that this does work if the Project language is set to Javascript.

Is this a known bug? I know that I should really be using the Set Variable keyword step, but I was surprised to find that this code snippet doesn't work


--------------------
Senior SQA Automation Engineer
1 ACCEPTED SOLUTION

Accepted Solutions
tphillips
Frequent Contributor

Re: Code Snippet operation with Python has syntax error when assigning variable value

I got a response from support:

"It appears that this code works perfectly fine in a script unit, but does not want to behave in the "run code snippet" operation. I was able to get it to work by wrapping it in exec("..."). For example, replace your code snippet operation with exec("KeywordTests.Test_Assigning.Variables.TestVar = 'String2'")"

 

I tried it out and it works fine. I guess this should be documented for python-specific weirdness?


--------------------
Senior SQA Automation Engineer

View solution in original post

5 REPLIES 5
sonya_m
Community Manager

Re: Code Snippet operation with Python has syntax error when assigning variable value

Hi @tphillips, looks like this behaviour can be reproduced indeed. Would you mind opening a support case? The Team would like to take a closer look at this. Thank you. 


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
tphillips
Frequent Contributor

Re: Code Snippet operation with Python has syntax error when assigning variable value

Cool thanks Sonya.

 

I have made a support ticket 🙂


--------------------
Senior SQA Automation Engineer
Hans748
Occasional Visitor

Re: Code Snippet operation with Python has syntax error when assigning variable value

Thanks for sharing this info this is useful. Keep it up

 

skylightpaycard

tphillips
Frequent Contributor

Re: Code Snippet operation with Python has syntax error when assigning variable value

I got a response from support:

"It appears that this code works perfectly fine in a script unit, but does not want to behave in the "run code snippet" operation. I was able to get it to work by wrapping it in exec("..."). For example, replace your code snippet operation with exec("KeywordTests.Test_Assigning.Variables.TestVar = 'String2'")"

 

I tried it out and it works fine. I guess this should be documented for python-specific weirdness?


--------------------
Senior SQA Automation Engineer

View solution in original post

sonya_m
Community Manager

Re: Code Snippet operation with Python has syntax error when assigning variable value

Great, thank you for sharing! I'll notify the doc team about this.


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: