Skip to content

Commit 78b65e1

Browse files
authored
Merge pull request #36 from redpanda-data/DEVPROD-2200
loader: add option to not fail if no tests are discovered
2 parents 482b3f6 + 2e16bba commit 78b65e1

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

ducktape/command_line/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ def main():
131131

132132
# Discover and load tests to be run
133133
loader = TestLoader(session_context, session_logger, repeat=args_dict["repeat"], injected_args=injected_args,
134-
subset=args_dict["subset"], subsets=args_dict["subsets"])
134+
subset=args_dict["subset"], subsets=args_dict["subsets"],
135+
allow_empty_tests_list=args_dict["allow_empty_tests_list"])
135136
try:
136137
tests = loader.load(args_dict["test_path"], excluded_test_symbols=args_dict['exclude'])
137138
except LoaderException as e:

ducktape/command_line/parse_args.py

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ def create_ducktape_parser():
100100
"to determine flakyness. When not present, deflake will not be used, "
101101
"and a test will be marked as either passed or failed. "
102102
"When enabled tests will be marked as flaky if it passes on any of the reruns")
103+
parser.add_argument("--allow-empty-tests-list", action="store_true",
104+
default=os.environ.get("DUCKTAPE_ALLOW_EMPTY_TESTS_LIST", "0").lower() in ("1", "true", "yes"),
105+
help="Proceeds without failing when no tests are loaded ")
103106
return parser
104107

105108

ducktape/tests/loader.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TestLoader(object):
5252
"""Class used to discover and load tests."""
5353

5454
def __init__(self, session_context, logger, repeat=1, injected_args=None, cluster=None, subset=0, subsets=1,
55-
historical_report=None):
55+
historical_report=None, allow_empty_tests_list=False):
5656
self.session_context = session_context
5757
self.cluster = cluster
5858
assert logger is not None
@@ -74,6 +74,7 @@ def __init__(self, session_context, logger, repeat=1, injected_args=None, cluste
7474
# A non-None value here means the loader will override the injected_args
7575
# in any discovered test, whether or not it is parametrized
7676
self.injected_args = injected_args
77+
self.allow_empty_tests_list = allow_empty_tests_list
7778

7879
def load(self, symbols, excluded_test_symbols=None):
7980
"""
@@ -146,7 +147,9 @@ def load(self, symbols, excluded_test_symbols=None):
146147
# Sort to make sure we get a consistent order for when we create subsets
147148
all_test_context_list = sorted(all_test_context_list, key=attrgetter("test_id"))
148149
if not all_test_context_list:
149-
raise LoaderException("No tests to run!")
150+
if not self.allow_empty_tests_list:
151+
raise LoaderException("No tests to run!")
152+
self.logger.warn("No tests to run!")
150153
self.logger.debug("Discovered these tests: " + str(all_test_context_list))
151154
# Select the subset of tests.
152155
if self.historical_report:

tests/loader/check_loader.py

+9
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,15 @@ def check_test_loader_raises_on_params_not_found(self):
403403
with pytest.raises(LoaderException, match='No tests to run'):
404404
loader.load(included)
405405

406+
def check_test_loader_allow_empty_tests_list(self):
407+
loader = TestLoader(self.SESSION_CONTEXT, logger=Mock(), allow_empty_tests_list=True)
408+
# parameter syntax is valid, but there is no such parameter defined in the test annotation in the code
409+
included = [os.path.join(discover_dir(), 'test_decorated.py::TestMatrix.test_thing@{"x": 1,"y": "missing"}')]
410+
try:
411+
loader.load(included)
412+
except LoaderException:
413+
pytest.fail("Should not have raised the LoaderException exception")
414+
406415
@pytest.mark.parametrize("symbol", [
407416
# no class
408417
'test_decorated.py::.test_thing'

0 commit comments

Comments
 (0)