Skip to content

Commit 240cdea

Browse files
committed
luatest: fix ability to run a test several times
It is a regression from commit 3b0ccd0 ("luatest: detox test searching code"), PR #433. The ability to run a test several times, especially in parallel, is very useful to reproduce and debug an unstable behavior in the test. Fixes #437
1 parent b8b60b4 commit 240cdea

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

lib/luatest_server.py

+24-9
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,26 @@ def find_tests(test_suite, suite_path):
180180

181181
tests = []
182182
for test_name in glob.glob(os.path.join(suite_path, '*_test.lua')):
183-
# If neither of the include patterns are substrings of
184-
# the given test name, skip the test.
185-
if not any(p in test_name for p in include_patterns):
183+
# Several include patterns may match the given
184+
# test[^1].
185+
#
186+
# The primary usage of this behavior is to run a test
187+
# many times in parallel to verify its stability or
188+
# to debug an unstable behavior.
189+
#
190+
# Execute the test once for each of the matching
191+
# patterns.
192+
#
193+
# [^1]: A pattern matches a test if the pattern is a
194+
# substring of the test name.
195+
repeat = sum(1 for p in include_patterns if p in test_name)
196+
# If neither of the include patterns matches the given
197+
# test, skip the test.
198+
if repeat == 0:
186199
continue
187200

188-
# If at least one of the exclude patterns is a
189-
# substring of the given test name, skip the test.
201+
# If at least one of the exclude patterns matches the
202+
# given test, skip the test.
190203
if any(p in test_name for p in exclude_patterns):
191204
continue
192205

@@ -211,13 +224,15 @@ def find_tests(test_suite, suite_path):
211224
prefix_len = len(os.path.commonprefix(test_cases))
212225

213226
for test_case in test_cases:
214-
tests.append(LuatestTest(test_name, test_suite.args, test_suite.ini,
215-
params={"test_case": test_case},
216-
conf_name=test_case[prefix_len:]))
227+
test_obj = LuatestTest(test_name, test_suite.args, test_suite.ini,
228+
params={"test_case": test_case},
229+
conf_name=test_case[prefix_len:])
230+
tests.extend([test_obj] * repeat)
217231
else:
218232
# If the test has no 'parallel' tag, run all the
219233
# test cases as one task.
220-
tests.append(LuatestTest(test_name, test_suite.args, test_suite.ini))
234+
test_obj = LuatestTest(test_name, test_suite.args, test_suite.ini)
235+
tests.extend([test_obj] * repeat)
221236

222237
tests.sort(key=lambda t: t.name)
223238

0 commit comments

Comments
 (0)