Skip to content

[BUG]: can't debug unit tests due to 'code' name collision #1126

@ericvergnaud

Description

@ericvergnaud

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When debugging unit tests using PyCharm pytest template, session fails with error:
ImportError: cannot import name 'InteractiveConsole' from 'code' (/Users/ericvergnaud/Development/databricks/ucx/tests/unit/code/__init__.py)

Expected Behavior

We should be able to debug unit tests

Steps To Reproduce

Use PyCharm
Uncomment test_runtime_delete_backup_groups in tests/unit/test_runtime.py
Try debugging via right-click

This issue is caused by our 'code' module which overrides the python 'code' module when running pytest.

Cloud

AWS

Operating System

macOS

Version

latest via Databricks CLI

Relevant log output

/Users/ericvergnaud/.pyenv/versions/3.12.2/bin/python3 -X pycache_prefix=/Users/ericvergnaud/Library/Caches/JetBrains/PyCharmCE2023.3/cpython-cache /Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 57247 --file /Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py --target test_runtime.py::test_runtime_apply_permissions_to_account_groups 
Testing started at 17:04 ...
Traceback (most recent call last):
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_console_integration.py", line 4, in <module>
    from code import InteractiveConsole, InteractiveInterpreter
ImportError: cannot import name 'InteractiveConsole' from 'code' (/Users/ericvergnaud/Development/databricks/ucx/tests/unit/code/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py", line 49, in <module>
    from _pydevd_bundle.pydevd_comm import CMD_SET_BREAK, CMD_SET_NEXT_STATEMENT, CMD_STEP_INTO, CMD_STEP_OVER, \
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 91, in <module>
    from _pydevd_bundle import pydevd_console_integration
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_console_integration.py", line 6, in <module>
    from _pydevd_bundle.pydevconsole_code_for_ironpython import IronPythonInteractiveConsole as InteractiveConsole, \
  File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevconsole_code_for_ironpython.py", line 305
    exec code in self.locals
    ^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'exec'. Did you mean exec(...)?

Process finished with exit code 1

Empty suite

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions