diff --git a/.flake8 b/.flake8 index 16851d91..9efa3bb1 100644 --- a/.flake8 +++ b/.flake8 @@ -7,5 +7,6 @@ max-line-length = 120 # D103 Missing docstring in public function # D104 Missing docstring in public package # D107 Missing docstring in __init__ +# W503 line break before binary operator # W606 'async' and 'await' are reserved keywords starting with Python 3.7 -ignore = D100, D101, D102, D103, D104, D107, W606 +ignore = D100, D101, D102, D103, D104, D107, W503, W606 diff --git a/unittesting/mixin.py b/unittesting/mixin.py index f4b490c3..2f8b1888 100644 --- a/unittesting/mixin.py +++ b/unittesting/mixin.py @@ -62,13 +62,6 @@ def current_package_name(self): return None - @property - def current_test_file(self): - current_file = sublime.active_window().active_view().file_name() - if current_file and current_file.endswith(".py"): - current_file = os.path.basename(current_file) - return current_file - def input_parser(self, package): m = re.match(r'([^:]+):(.+)', package) if m: diff --git a/unittesting/test_current.py b/unittesting/test_current.py index 16a321ea..6a1e01b9 100644 --- a/unittesting/test_current.py +++ b/unittesting/test_current.py @@ -1,3 +1,5 @@ +from fnmatch import fnmatch +import os import sublime import sys from .test_package import UnitTestingCommand @@ -43,9 +45,23 @@ def run(self, **kwargs): sublime.message_dialog("Cannot determine package name.") return - test_file = self.current_test_file - if not test_file: - test_file = "" + window = sublime.active_window() + if not window: + return + + view = window.active_view() + + settings = self.load_unittesting_settings(project_name, kwargs) + current_file = (view and view.file_name()) or '' + file_name = os.path.basename(current_file) + if file_name and fnmatch(file_name, settings['pattern']): + test_file = file_name + window.settings().set('UnitTesting.last_test_file', test_file) + else: + test_file = ( + window.settings().get('UnitTesting.last_test_file') + or current_file + ) sublime.set_timeout_async( lambda: super(UnitTestingCurrentFileCommand, self).run(