Skip to content

Commit 3b0ccd0

Browse files
Totktonadaylobankov
authored andcommitted
luatest: detox test searching code
It is hard to understand and hard to extend. This commit attempts to arrange the method. Points to highlight: * Two old hacks are kept as is and got TODO comments. I'm a bit worrying about compatibility here and I would return here back later. * `tests` and `exclude` patterns are obtained directly from the CLI options object, because I don't see a reason to pass them over the test suite object. * `Server.exclude_tests` helper is not used anymore. A filtering by tags is included right into the test searching method. * All the filtering conditions are expressed in a similar way, so more ones may be added in a future.
1 parent 1fbbf9a commit 3b0ccd0

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

lib/luatest_server.py

+42-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from lib.tarantool_server import Test
1515
from lib.tarantool_server import TestExecutionError
1616
from lib.tarantool_server import TarantoolServer
17+
from lib.utils import find_tags
1718

1819

1920
def timeout_handler(process, test_timeout):
@@ -141,18 +142,46 @@ def verify_luatest_exe(cls):
141142
def find_tests(test_suite, suite_path):
142143
"""Looking for *_test.lua, which are can be executed by luatest."""
143144

144-
def patterned(test, patterns):
145-
answer = []
146-
for i in patterns:
147-
if test.name.find(i) != -1:
148-
answer.append(test)
149-
return answer
150-
145+
# TODO: Investigate why this old hack is needed and drop
146+
# it if possible (move the assignment to test_suite.py).
147+
#
148+
# cdc70f94701f suggests that it is related to the out of
149+
# source build.
151150
test_suite.ini['suite'] = suite_path
152-
tests = glob.glob(os.path.join(suite_path, '*_test.lua'))
153151

154-
tests = Server.exclude_tests(tests, test_suite.args.exclude)
155-
test_suite.tests = [LuatestTest(k, test_suite.args, test_suite.ini)
156-
for k in sorted(tests)]
157-
test_suite.tests = sum([patterned(x, test_suite.args.tests)
158-
for x in test_suite.tests], [])
152+
# A pattern here means just a substring to find in a test
153+
# name.
154+
include_patterns = Options().args.tests
155+
exclude_patterns = Options().args.exclude
156+
157+
accepted_tags = Options().args.tags
158+
159+
tests = []
160+
for test_name in glob.glob(os.path.join(suite_path, '*_test.lua')):
161+
# If neither of the include patterns are substrings of
162+
# the given test name, skip the test.
163+
if not any(p in test_name for p in include_patterns):
164+
continue
165+
166+
# If at least one of the exclude patterns is a
167+
# substring of the given test name, skip the test.
168+
if any(p in test_name for p in exclude_patterns):
169+
continue
170+
171+
# If --tags <...> CLI option is provided...
172+
if accepted_tags:
173+
tags = find_tags(test_name)
174+
# ...and the test has neither of the given tags,
175+
# skip the test.
176+
if not any(t in accepted_tags for t in tags):
177+
continue
178+
179+
# Add the test to the execution list otherwise.
180+
tests.append(LuatestTest(test_name, test_suite.args, test_suite.ini))
181+
182+
tests.sort(key=lambda t: t.name)
183+
184+
# TODO: Don't modify a test suite object's field from
185+
# another object directly. It is much better to just
186+
# return a list of tests from this method.
187+
test_suite.tests = tests

0 commit comments

Comments
 (0)