Skip to content

Commit 01598b7

Browse files
committed
Fix ducktape test runner: robust argument handling
- Handle both old and new script versions gracefully - Default to producer tests when no arguments provided - Support multiple argument formats: * No args: run all producer tests * test_type (producer/consumer/producer_sr): run specific test type * test_file.py: run specific test file * test_method: run specific test method - Fixes IndexError in Semaphore when script called without arguments - Backward compatible with existing usage patterns
1 parent ad181f2 commit 01598b7

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

tests/ducktape/run_ducktape_test.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,30 @@ def main():
5656
return 1
5757

5858
# Get test file path (ducktape expects file paths, not module paths)
59+
# ROBUST FIX: Handle both old and new script versions
5960
test_dir = os.path.dirname(os.path.abspath(__file__))
60-
test_file = os.path.join(test_dir, "test_producer.py")
61+
62+
# Default to producer tests if no arguments provided
63+
if len(sys.argv) > 1:
64+
# Arguments provided - use the first one as test file or test type
65+
arg = sys.argv[1]
66+
if arg in ['producer', 'consumer', 'producer_sr']:
67+
# New argparse-style argument - map to test file
68+
test_files = {
69+
'producer': 'test_producer.py',
70+
'consumer': 'test_consumer.py',
71+
'producer_sr': 'test_producer_with_schema_registry.py'
72+
}
73+
test_file = os.path.join(test_dir, test_files[arg])
74+
elif arg.endswith('.py'):
75+
# Direct test file specified
76+
test_file = os.path.join(test_dir, arg)
77+
else:
78+
# Assume it's a test method name, use default producer file
79+
test_file = os.path.join(test_dir, "test_producer.py")
80+
else:
81+
# No arguments - default to producer tests
82+
test_file = os.path.join(test_dir, "test_producer.py")
6183

6284
if not os.path.exists(test_file):
6385
print(f"ERROR: Test file not found: {test_file}")
@@ -81,13 +103,18 @@ def main():
81103
test_file
82104
]
83105

84-
# Add specific test if provided as argument
85-
if len(sys.argv) > 1:
106+
# Add specific test method if provided as second argument
107+
if len(sys.argv) > 2:
108+
test_method = sys.argv[2]
109+
cmd[-1] = f"{test_file}::{test_method}"
110+
print(f"Running specific test: {test_method}")
111+
elif len(sys.argv) > 1 and not sys.argv[1].endswith('.py') and sys.argv[1] not in ['producer', 'consumer', 'producer_sr']:
112+
# First argument is a test method name (old behavior)
86113
test_method = sys.argv[1]
87114
cmd[-1] = f"{test_file}::{test_method}"
88115
print(f"Running specific test: {test_method}")
89116
else:
90-
print("Running all producer tests")
117+
print("Running all tests in the file")
91118

92119
print("Command:", " ".join(cmd))
93120
print()

0 commit comments

Comments
 (0)