enthought / envisage

Envisage is a Python-based framework for building applications whose functionalities can be extended by adding "plug-ins".
http://docs.enthought.com/envisage/
Other
82 stars 26 forks source link

EggPluginManager tests fail when run standalone #563

Closed mdickinson closed 1 year ago

mdickinson commented 1 year ago

The test_egg_plugin_manager test fails when run standalone, but passes as part of a complete test run (using python -m unittest).

(envisage) mdickinson@mirzakhani envisage % python -m unittest envisage.tests.test_egg_plugin_manager
.EEEE.
======================================================================
ERROR: test_exclude_specific (envisage.tests.test_egg_plugin_manager.EggPluginManagerTestCase.test_exclude_specific)
exclude specific
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/tests/test_egg_plugin_manager.py", line 116, in test_exclude_specific
    self._test_start_and_stop(plugin_manager, expected)
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/tests/test_egg_plugin_manager.py", line 170, in _test_start_and_stop
    self.assertEqual(expected, [plugin.id for plugin in plugin_manager])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/plugin_manager.py", line 104, in __iter__
    for plugin in self._plugins
                  ^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/egg_plugin_manager.py", line 98, in __plugins_default
    plugin = self._create_plugin_from_ep(ep)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/egg_plugin_manager.py", line 117, in _create_plugin_from_ep
    klass = ep.load()
            ^^^^^^^^^
  File "/Users/mdickinson/.venvs/envisage/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2517, in load
    return self.resolve()
           ^^^^^^^^^^^^^^
  File "/Users/mdickinson/.venvs/envisage/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2523, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'acme_bar'

======================================================================
ERROR: test_include_multiple (envisage.tests.test_egg_plugin_manager.EggPluginManagerTestCase.test_include_multiple)
include multiple
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/tests/test_egg_plugin_manager.py", line 91, in test_include_multiple
    self._test_start_and_stop(plugin_manager, expected)
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/tests/test_egg_plugin_manager.py", line 170, in _test_start_and_stop
    self.assertEqual(expected, [plugin.id for plugin in plugin_manager])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/plugin_manager.py", line 104, in __iter__
    for plugin in self._plugins
                  ^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/egg_plugin_manager.py", line 98, in __plugins_default
    plugin = self._create_plugin_from_ep(ep)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/egg_plugin_manager.py", line 117, in _create_plugin_from_ep
    klass = ep.load()
            ^^^^^^^^^
  File "/Users/mdickinson/.venvs/envisage/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2517, in load
    return self.resolve()
           ^^^^^^^^^^^^^^
  File "/Users/mdickinson/.venvs/envisage/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2523, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'acme_bar'

======================================================================
ERROR: test_include_specific (envisage.tests.test_egg_plugin_manager.EggPluginManagerTestCase.test_include_specific)
include specific
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/tests/test_egg_plugin_manager.py", line 69, in test_include_specific
    self._test_start_and_stop(plugin_manager, expected)
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/tests/test_egg_plugin_manager.py", line 170, in _test_start_and_stop
    self.assertEqual(expected, [plugin.id for plugin in plugin_manager])
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/plugin_manager.py", line 104, in __iter__
    for plugin in self._plugins
                  ^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/egg_plugin_manager.py", line 98, in __plugins_default
    plugin = self._create_plugin_from_ep(ep)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/egg_plugin_manager.py", line 117, in _create_plugin_from_ep
    klass = ep.load()
            ^^^^^^^^^
  File "/Users/mdickinson/.venvs/envisage/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2517, in load
    return self.resolve()
           ^^^^^^^^^^^^^^
  File "/Users/mdickinson/.venvs/envisage/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2523, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'acme_bar'

======================================================================
ERROR: test_no_include_or_exclude (envisage.tests.test_egg_plugin_manager.EggPluginManagerTestCase.test_no_include_or_exclude)
no include or exclude
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/tests/test_egg_plugin_manager.py", line 44, in test_no_include_or_exclude
    ids = [plugin.id for plugin in plugin_manager]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/plugin_manager.py", line 104, in __iter__
    for plugin in self._plugins
                  ^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/egg_plugin_manager.py", line 98, in __plugins_default
    plugin = self._create_plugin_from_ep(ep)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mdickinson/Enthought/ETS/envisage/envisage/egg_plugin_manager.py", line 117, in _create_plugin_from_ep
    klass = ep.load()
            ^^^^^^^^^
  File "/Users/mdickinson/.venvs/envisage/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2517, in load
    return self.resolve()
           ^^^^^^^^^^^^^^
  File "/Users/mdickinson/.venvs/envisage/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2523, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'acme_bar'

----------------------------------------------------------------------
Ran 6 tests in 2.110s

FAILED (errors=4)
mdickinson commented 1 year ago

Note: this is with the latest setuptools version and Python 3.11.

The problem appears to be that our code mutates the pkg_resources WorkingSet, and then to compensate, replaces it with a fresh WorkingSet at tearDown time.

The original pkg_resources.WorkingSet has a callback registered that modifies sys.path. The replacement WorkingSet does not seem to have that callback registered, so sys.path isn't being modified in the second and subsequent tests.

mdickinson commented 1 year ago

Related issue: the test suite also currently fails under haas. We should double check with haas before closing this issue.