UnitTesting
UnitTesting copied to clipboard
Test Current File ImportError failed to imports tests (ST4)
In ST4 the Test Current File command errors with the following:
tests (unittest.loader._FailedTest) ... ERROR
======================================================================
ERROR: tests (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests
Traceback (most recent call last):
File "./python3.8/unittest/loader.py", line 470, in _find_test_path
File "./python3.8/unittest/loader.py", line 377, in _get_module_from_name
File "/home/gerard/.config/sublime-text/Packages/PHPUnitKit/tests/__init__.py", line 7, in <module>
sublime_plugin.reload_plugin('PHPUnitKit.tests.commands')
File "/home/gerard/sublime_text_4/Lib/python38/sublime_plugin.py", line 325, in reload_plugin
m = importlib.import_module(modulename)
File "./python3.8/importlib/__init__.py", line 127, in import_module
ModuleNotFoundError: No module named 'PHPUnitKit.tests'
----------------------------------------------------------------------
Ran 1 test in 0.029s
This can be reproduced by testing PHPUnitKit.
I think it has something to do with the reloader. In PHPUnitKit the tests load some commands through tests/__init__.py: https://github.com/gerardroche/sublime-phpunit/blob/master/tests/init.py
import sublime_plugin
# Sublime Text loads all modules in the root package and initialises all
# commands found in all of those modules. The tests commands are not located in
# the root project because they are only required by the tests. So they need to
# loaded, or "reloaded", when the tests are run.
sublime_plugin.reload_plugin('PHPUnitKit.tests.commands')