Trying to debug a pytest unit test gives me
exec code in self.locals SyntaxError: Missing parentheses in call to 'exec'
on very simple code.
What could be causing it?
The Python "SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?" occurs when we forget to call print() as a function. To solve the error, call the print function with parenthesis, e.g. print('hello world') .
This error message means that you are attempting to use Python 3 to follow an example or run a program that uses the Python 2 print statement: print "Hello, World!" The statement above does not work in Python 3. In Python 3 you need to add parentheses around the value to be printed: print("Hello, World!")
The Python “SyntaxError: Missing parentheses in call to 'print'” error is raised when you try to print a value to the console without enclosing that value in parenthesis. To solve this error, add parentheses around any statements you want to print to the console. This is because, in Python 3, print is not a statement.
The Python “SyntaxError: Missing parentheses in call to ‘print’” error is raised when you try to print a value to the console without enclosing that value in parenthesis. To solve this error, add parentheses around any statements you want to print to the console. This is because, in Python 3, print is not a statement. It is a function.
To solve the error, call the print function with parenthesis, e.g. print ('hello world'). Here is an example of how the error occurs. name = 'Alice' # ⛔️ SyntaxError: Missing parentheses in call to 'print'. Did you mean print (...)? print 'hello ' + name The code above uses print as a statement, which is the older syntax that was used in Python 2.
Since the "Missing parentheses in call to print" case is a compile time syntax error and hence has access to the raw source code, it's able to include the full text on the rest of the line in the suggested replacement.
You must call a function using parentheses if you want to run it. Now you have the knowledge you need to fix this common Python error like a pro! About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers.
Don't have a module named code
in your code, because it conflicts with pytest.
Changing to src
solved this.
I found the answer here:
it turned out to be a conflict with my own python module called 'code' and one in use by the debugger. I changed my module name and the debugger began working. This article pointed me to the solution: https://superuser.com/questions/1385995/my-pycharm-run-is-working-but-debugging-is-failing
This took me a while to find, so I thought I'd post it here for easy googling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With