From d3f1b00ecf4ae0567f31ea06b64629978d444c0c Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 1 Nov 2025 11:35:59 +0100 Subject: [PATCH] Fix test module imports This commit modifies `top_level_dir`, which is used to resolve module names when loading unittests, to ensure, only modules from specified ST package are importet. Without this commit, UnitTesting might attempt to import packages/modules/tests from Lib/ directory due to possible ambiguities. Scenario: Plugins of `MyPackage` are organized in `Packages/MyPackage/dirname/` and tests in `Packages/MyPackage/dirname/tests/`. If a library `Lib/pythonXX/dirname` exists, Unittesting would have attempted to import tests from that directory, because test module paths would have been translated to `dirname.tests` due to `top_level_dir` pointing to `Packages/MyPackage`. By adjusting `top_level_dir` to `Packages/`, test module names are translated to `MyPackage.dirname.tests` instead. --- unittesting/unit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittesting/unit.py b/unittesting/unit.py index 41f05c33..3577f294 100644 --- a/unittesting/unit.py +++ b/unittesting/unit.py @@ -221,7 +221,7 @@ def run_tests(self, stream, package, settings, cleanup_hooks): loader = DeferrableTestLoader(settings["deferred"]) if os.path.exists(os.path.join(start_dir, "__init__.py")): tests = loader.discover( - start_dir, settings["pattern"], top_level_dir=package_dir + start_dir, settings["pattern"], top_level_dir=sublime.packages_path() ) else: tests = loader.discover(start_dir, settings["pattern"])