diff --git a/nose2/plugins/loader/eggdiscovery.py b/nose2/plugins/loader/eggdiscovery.py index ce539df7..1928aa67 100644 --- a/nose2/plugins/loader/eggdiscovery.py +++ b/nose2/plugins/loader/eggdiscovery.py @@ -17,7 +17,6 @@ import logging import os -import types from nose2 import events from nose2.plugins.loader import discovery @@ -26,11 +25,11 @@ log = logging.getLogger(__name__) try: - import pkg_resources as _pkg_resources_mod + import pkg_resources - pkg_resources: types.ModuleType | None = _pkg_resources_mod + _has_pkg_resources = True except ImportError: - pkg_resources = None + _has_pkg_resources = False class EggDiscoveryLoader(events.Plugin, discovery.Discoverer): @@ -85,7 +84,7 @@ def _find_tests_in_egg_dir(self, event, rel_path, dist): def _find_tests_in_dir(self, event, full_path, top_level): if os.path.exists(full_path): return - elif pkg_resources and full_path.find(".egg") != -1: + elif _has_pkg_resources and full_path.find(".egg") != -1: egg_path = full_path.split(".egg")[0] + ".egg" for dist in pkg_resources.find_distributions(egg_path): for modname in dist._get_metadata("top_level.txt"): diff --git a/nose2/tests/functional/test_eggdiscovery_loader.py b/nose2/tests/functional/test_eggdiscovery_loader.py index 367492fd..a7bd0be0 100644 --- a/nose2/tests/functional/test_eggdiscovery_loader.py +++ b/nose2/tests/functional/test_eggdiscovery_loader.py @@ -6,11 +6,9 @@ from nose2.tests._common import FunctionalTestCase, support_file try: - import pkg_resources - + import pkg_resources # noqa: F401 except ImportError: - pkg_resources = None - + pass else: class EggDiscoveryFunctionalTest(FunctionalTestCase):