提交 cdf908ec 编写于 作者: L Lukáš Doktor

avocado.core.loader: Fix subtests filter

We used to support subtests filter to load only some of the avocado
tests, but the functionality is broken. This patch brings this
functionality back. It uses "re.search" so people can use partial
matches. Additionally it includes selftests to prevent future breakages.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 d00da48c
......@@ -487,10 +487,11 @@ class FileLoader(TestLoader):
_url, _subtests_filter = url.split(':', 1)
if os.path.exists(_url): # otherwise it's ':' in the file name
url = _url
subtests_filter = _subtests_filter
subtests_filter = re.compile(_subtests_filter)
if not os.path.isdir(url): # Single file
if not self._make_tests(url, DEFAULT, subtests_filter):
if (not self._make_tests(url, DEFAULT, subtests_filter) and
not subtests_filter):
split_url = shlex.split(url)
if (os.access(split_url[0], os.X_OK) and
not os.path.isdir(split_url[0])):
......@@ -620,6 +621,9 @@ class FileLoader(TestLoader):
for test_method in test_methods:
name = test_name + \
':%s.%s' % (test_class, test_method)
if (subtests_filter and
not subtests_filter.search(name)):
continue
tst = (test_class, {'name': name,
'modulePath': test_path,
'methodName': test_method})
......
......@@ -221,6 +221,23 @@ class LoaderTest(unittest.TestCase):
avocado_multiple_tests.save()
suite = self.loader.discover(avocado_multiple_tests.path, True)
self.assertEqual(len(suite), 2)
# Try to load only some of the tests
suite = self.loader.discover(avocado_multiple_tests.path +
':MultipleMethods.testTwo', True)
self.assertEqual(len(suite), 1)
self.assertEqual(suite[0][1]["methodName"], 'testTwo')
# Load using regexp
suite = self.loader.discover(avocado_multiple_tests.path +
':.*_one', True)
self.assertEqual(len(suite), 1)
self.assertEqual(suite[0][1]["methodName"], 'test_one')
# Load booth
suite = self.loader.discover(avocado_multiple_tests.path +
':test.*', True)
self.assertEqual(len(suite), 2)
# Load none should return no tests
self.assertTrue(not self.loader.discover(avocado_multiple_tests.path +
":no_match", True))
avocado_multiple_tests.remove()
def test_load_foreign(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册