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

Viewed 3320

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?

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.

Related