Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytest exec code in self.locals SyntaxError: Missing parentheses in call to 'exec'

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?

like image 814
Gulzar Avatar asked May 09 '20 11:05

Gulzar


People also ask

How do you fix missing parentheses in call to print?

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') .

What does missing parentheses mean in Python?

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!")

What error do you get if you miss an open parentheses in Python?

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.

How do you fix syntax error missing parentheses in Python?

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.

How do I solve a syntax error when calling the print 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.

Why is there a missing parentheses in call to print?

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.

Do you need parentheses to call a function in Python?

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.


1 Answers

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.

like image 183
Gulzar Avatar answered Oct 10 '22 22:10

Gulzar