Open
Description
I had imported another test file, in one (main) test file like this:
from .text_extraction_unit_tests import PrefixStrippingViewUnitTests
wrap_plus_module = sys.modules["Wrap Plus.wrap_plus"]
def run_unit_tests(unit_tests_to_run=[]):
runner = unittest.TextTestRunner()
classes = \
[
PrefixStrippingViewUnitTests,
SemanticLineWrapUnitTests,
LineBalancingUnitTests,
]
if len( unit_tests_to_run ) < 1:
# Comment all the tests names on this list, to run all Unit Tests
unit_tests_to_run = \
[
# "test_semantic_line_wrap_line_starting_with_comment",
# "test_split_lines_with_trailing_new_line",
# "test_split_lines_without_trailing_new_line",
# "test_balance_characters_between_line_wraps_with_trailing_new_line",
# "test_balance_characters_between_line_wraps_without_trailing_new_line",
# "test_balance_characters_between_line_wraps_ending_with_long_word",
]
runner.run( suite( classes, unit_tests_to_run ) )
def suite(classes, unit_tests_to_run):
"""
Problem with sys.argv[1] when unittest module is in a script
https://stackoverflow.com/questions/2812218/problem-with-sys-argv1-when-unittest-module
Is there a way to loop through and execute all of the functions in a Python class?
https://stackoverflow.com/questions/2597827/is-there-a-way-to-loop-through-and-execute
looping over all member variables of a class in python
https://stackoverflow.com/questions/1398022/looping-over-all-member-variables-of-a-class
"""
suite = unittest.TestSuite()
unit_tests_to_run_count = len( unit_tests_to_run )
for _class in classes:
_object = _class()
for function_name in dir( _object ):
if function_name.lower().startswith( "test" ):
if unit_tests_to_run_count > 0 \
and function_name not in unit_tests_to_run:
continue
suite.addTest( _class( function_name ) )
return suite
Using this I can run the unit tests by my loader file inside the file Wrap Plus.wrap_plus
:
def run_tests():
"""
How do I unload (reload) a Python module?
https://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module
"""
print( "\n\n" )
sublime_plugin.reload_plugin( "Wrap Plus.tests.text_extraction_unit_tests" )
sublime_plugin.reload_plugin( "Wrap Plus.tests.semantic_linefeed_unit_tests" )
sublime_plugin.reload_plugin( "Wrap Plus.tests.semantic_linefeed_manual_tests" )
from .tests import semantic_linefeed_unit_tests
# Comment all the tests names on this list, to run all Unit Tests
unit_tests_to_run = \
[
# "test_semantic_line_wrap_ending_with_comma_list",
# "test_is_command_separated_list_5_items",
# "test_is_command_separated_list_4_items",
# "test_is_command_separated_list_3_items",
# "test_is_command_separated_list_2_items",
]
semantic_linefeed_unit_tests.run_unit_tests( unit_tests_to_run )
def plugin_loaded():
"""
Running single test from unittest.TestCase via command line
https://stackoverflow.com/questions/15971735/running-single-test-from-unittest-testcase
"""
run_tests()
And it successfully run I reload the Wrap Plus.wrap_plus
file:
reloading plugin Wrap Plus.tests.text_extraction_unit_tests
reloading plugin Wrap Plus.tests.semantic_linefeed_unit_tests
reloading plugin Wrap Plus.tests.semantic_linefeed_manual_tests
...................................................
----------------------------------------------------------------------
Ran 51 tests in 0.601s
OK
reloading plugin Wrap Plus.wrap_plus
But when I use the UnitTesting
command UnitTesting: Test Current Package
, I got this error:
semantic_linefeed_unit_tests (unittest.loader.ModuleImportFailure) ... ERROR
test_double_quotes_wrappting (text_extraction_unit_tests.PrefixStrippingViewUnitTests) ... ok
test_double_quotes_wrappting_without_leading_whitespace (text_extraction_unit_tests.PrefixStrippingViewUnitTests) ... ok
test_triple_quotes_comment (text_extraction_unit_tests.PrefixStrippingViewUnitTests) ... ok
test_triple_quotes_wrappting (text_extraction_unit_tests.PrefixStrippingViewUnitTests) ... ok
test_triple_quotes_wrappting_without_leading_whitespace (text_extraction_unit_tests.PrefixStrippingViewUnitTests) ... ok
======================================================================
ERROR: semantic_linefeed_unit_tests (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./python3.3/unittest/case.py", line 384, in _executeTestPart
File "./python3.3/unittest/loader.py", line 32, in testFailure
ImportError: Failed to import test module: semantic_linefeed_unit_tests
Traceback (most recent call last):
File "./python3.3/unittest/loader.py", line 261, in _find_tests
File "./python3.3/unittest/loader.py", line 239, in _get_module_from_name
File "D:\SublimeText\Data\Packages\Wrap Plus\tests\semantic_linefeed_unit_tests.py", line 11, in <module>
from .text_extraction_unit_tests import PrefixStrippingViewUnitTests
SystemError: Parent module '' not loaded, cannot perform relative import
----------------------------------------------------------------------
Ran 6 tests in 0.544s
FAILED (errors=1)
UnitTesting: Done.
Metadata
Metadata
Assignees
Labels
No labels