enthought / enthought/traitsui

SystemError when instantiating UITester on Python 3.6.0

Open
#1,505 0 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
Python
Stars
306
Forks
99
PR merge metrics
No merged PRs in 30d

Description

[From enthought/traits#1426]

Instantiating the `UITester` on Python 3.6.0 gives a `SystemError`. The root cause seems to be this call to `import_module`: https://github.com/enthought/traitsui/blob/79b66f5670e3de2b73529db5c29b3d216f0a2389/traitsui/testing/tester/_ui_tester_registry/default_registry.py#L38-L41

At the point where `import_module` is called, the module described by `this_package + '.' + toolkit` has not already been imported, so it's not in `sys.modules`.

Note that the behaviour was changed in Python 3.6.3, so later versions of Python 3.6 don't have this problem. See https://bugs.python.org/issue30876

If we want to fix this in TraitsUI, the fix is to make sure that the base package has been imported before we try to import the `default_registry` module.

Demonstration:
```
mdickinson@mirzakhani Desktop % edm env create testing --force --version 3.6.0
Removing environment: testing
Fetching indices for runtime repositories. done
Installing runtime... done
Fetching indices for package repositories... done
Installing/removing package(s)
setuptools [...................................................................................................................................]
mdickinson@mirzakhani Desktop % edm install -e testing traitsui pyqt5
Fetching indices for package repositories... done

The following packages will be installed:

icu4c 50.2-2 10.69 MiB
importlib_metadata 2.0.0-1 59 KiB
importlib_resources 3.3.0-1 58 KiB
libjpeg 7.0-5 268 KiB
libpng 1.6.36-5 447 KiB
libxml2 2.9.7-1 1.38 MiB
libxslt 1.1.30-1 320 KiB
pyface 7.2.0-2 2.21 MiB
pyqt5 5.14.2-3 5.44 MiB
pyqt5_sip 12.7.2-1 76 KiB
qt 5.12.6-7 50.61 MiB
traits 6.2.0-1 5.35 MiB
traitsui 7.1.1-3 2.51 MiB
zipp 3.4.0-2 10 KiB

Do you want to continue ? [Y/n]: y
Installing/removing package(s)
traitsui [.................................................................................................................................]
mdickinson@mirzakhani Desktop % edm run -e testing python
Enthought Deployment Manager -- https://www.enthought.com
Python 3.6.0 |Enthought, Inc. (x86_64)| (default, Feb 25 2020, 20:22:24)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from traitsui.testing.api import UITester
>>> tester = UITester()
Traceback (most recent call last):
File "", line 1, in
File "/Users/mdickinson/.edm/envs/testing/lib/python3.6/site-packages/traitsui/testing/tester/ui_tester.py", line 65, in __init__
self._registries.append(get_default_registry())
File "/Users/mdickinson/.edm/envs/testing/lib/python3.6/site-packages/traitsui/testing/tester/_ui_tester_registry/default_registry.py", line 41, in get_default_registry
this_package + '.' + toolkit)
File "/Users/mdickinson/.edm/envs/testing/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 973, in _gcd_import
File "", line 923, in _sanity_check
SystemError: Parent module 'traitsui.testing.tester._ui_tester_registry.qt4' not loaded, cannot perform relative import
>>>
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.