Skip to content

Commit d9bfc49

Browse files
Copilotdev-ankit
andcommitted
Consolidate output format flags into --output/-o
Co-authored-by: dev-ankit <1901680+dev-ankit@users.noreply.github.com>
1 parent 2820960 commit d9bfc49

5 files changed

Lines changed: 46 additions & 47 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ python3 compare_runs.py test_runs/HTML-Report-292/report.csv test_runs/HTML-Repo
3030
- JSON output for scripting:
3131

3232
```
33-
python3 compare_runs.py test_runs/HTML-Report-292 test_runs/HTML-Report-294 --json
33+
python3 compare_runs.py test_runs/HTML-Report-292 test_runs/HTML-Report-294 -o json
3434
```
3535

36-
- Colorize output and show verdicts (green=better, red=worse):
36+
- Markdown output with emoji indicators (✅ better, worse, ➖ same):
3737

3838
```
39-
python3 compare_runs.py test_runs/HTML-Report-292 test_runs/HTML-Report-294 --color
39+
python3 compare_runs.py test_runs/HTML-Report-292 test_runs/HTML-Report-294 -o markdown
4040
```
4141

42-
- Markdown output with emoji indicators (✅ better, worse, ➖ same):
42+
- Colorize text output (green=better, red=worse):
4343

4444
```
45-
python3 compare_runs.py test_runs/HTML-Report-292 test_runs/HTML-Report-294 --markdown
45+
python3 compare_runs.py test_runs/HTML-Report-292 test_runs/HTML-Report-294 --color
4646
```
4747

4848
Exit code is `0` on success and `1` on error.
@@ -69,7 +69,7 @@ If a metric is not available for an item, it is shown as `-`.
6969

7070
## Markdown Output Example
7171

72-
The `--markdown` flag produces markdown tables with emoji indicators for verdicts:
72+
The `-o markdown` flag produces markdown tables with emoji indicators for verdicts:
7373

7474
```markdown
7575
## Aggregated

compare_runs.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,10 @@ def render_comparison(
504504
def compare_reports(
505505
base_path: Path,
506506
curr_path: Path,
507-
as_json: bool = False,
507+
output_format: str = "text",
508508
*,
509509
colorize: bool = False,
510510
show_verdict: bool = True,
511-
as_markdown: bool = False,
512511
) -> int:
513512
# Resolve paths (extract zip files if needed)
514513
base_path = _resolve_path(base_path)
@@ -537,7 +536,7 @@ def compare_reports(
537536
base_html_map = load_html_feature_map(base_path if base_path.is_dir() else base_path.parent)
538537
curr_html_map = load_html_feature_map(curr_path if curr_path.is_dir() else curr_path.parent)
539538

540-
if as_json:
539+
if output_format == "json":
541540
# Produce a structured JSON dict
542541
out: Dict[str, Dict[str, Dict[str, Optional[float]]]] = {}
543542
for key in all_keys:
@@ -589,7 +588,7 @@ def compare_reports(
589588
return 0
590589

591590
# Human readable output
592-
if as_markdown:
591+
if output_format == "markdown":
593592
print("# Locust Performance Comparison")
594593
print("")
595594
print_section_markdown("Aggregated", 2)
@@ -681,16 +680,17 @@ def main():
681680
)
682681
parser.add_argument("base", type=Path, help="Base run directory or report.csv path")
683682
parser.add_argument("current", type=Path, help="Current run directory or report.csv path")
684-
parser.add_argument("--json", action="store_true", help="Output results as JSON")
685683
parser.add_argument(
686-
"--markdown",
687-
action="store_true",
688-
help="Output results as Markdown with emoji indicators (✅ better, ❌ worse, ➖ same)",
684+
"-o",
685+
"--output",
686+
choices=["text", "json", "markdown"],
687+
default="text",
688+
help="Output format: text (default), json, or markdown with emoji indicators (✅ better, ❌ worse, ➖ same)",
689689
)
690690
parser.add_argument(
691691
"--color",
692692
action="store_true",
693-
help="Colorize rows: green if better, red if worse",
693+
help="Colorize rows: green if better, red if worse (only for text output)",
694694
)
695695
parser.add_argument(
696696
"--no-verdict",
@@ -704,10 +704,9 @@ def main():
704704
return compare_reports(
705705
args.base,
706706
args.current,
707-
as_json=args.json,
707+
output_format=args.output,
708708
colorize=args.color,
709709
show_verdict=args.show_verdict,
710-
as_markdown=args.markdown,
711710
)
712711
except Exception as e:
713712
print(f"Error: {e}")

tests/test_compare_reports.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TestCompareReportsJson:
1515
"""Tests for compare_reports with JSON output."""
1616

1717
def test_json_output_structure(self, temp_test_dir, temp_test_dir_v2, capsys):
18-
result = compare_reports(temp_test_dir, temp_test_dir_v2, as_json=True)
18+
result = compare_reports(temp_test_dir, temp_test_dir_v2, output_format="json")
1919
assert result == 0
2020

2121
captured = capsys.readouterr()
@@ -27,7 +27,7 @@ def test_json_output_structure(self, temp_test_dir, temp_test_dir_v2, capsys):
2727
assert "/api/login" in data
2828

2929
def test_json_output_metrics(self, temp_test_dir, temp_test_dir_v2, capsys):
30-
compare_reports(temp_test_dir, temp_test_dir_v2, as_json=True)
30+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="json")
3131

3232
captured = capsys.readouterr()
3333
data = json.loads(captured.out)
@@ -42,7 +42,7 @@ def test_json_output_metrics(self, temp_test_dir, temp_test_dir_v2, capsys):
4242
assert "pct_change" in metric
4343

4444
def test_json_output_values(self, temp_test_dir, temp_test_dir_v2, capsys):
45-
compare_reports(temp_test_dir, temp_test_dir_v2, as_json=True)
45+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="json")
4646

4747
captured = capsys.readouterr()
4848
data = json.loads(captured.out)
@@ -61,7 +61,7 @@ class TestCompareReportsHuman:
6161
"""Tests for compare_reports with human-readable output."""
6262

6363
def test_human_output_includes_sections(self, temp_test_dir, temp_test_dir_v2, capsys):
64-
result = compare_reports(temp_test_dir, temp_test_dir_v2, as_json=False)
64+
result = compare_reports(temp_test_dir, temp_test_dir_v2, output_format="text")
6565
assert result == 0
6666

6767
captured = capsys.readouterr()
@@ -72,7 +72,7 @@ def test_human_output_includes_sections(self, temp_test_dir, temp_test_dir_v2, c
7272
assert "Endpoint:" in output
7373

7474
def test_human_output_includes_metrics(self, temp_test_dir, temp_test_dir_v2, capsys):
75-
compare_reports(temp_test_dir, temp_test_dir_v2, as_json=False)
75+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="text")
7676

7777
captured = capsys.readouterr()
7878
output = captured.out
@@ -83,7 +83,7 @@ def test_human_output_includes_metrics(self, temp_test_dir, temp_test_dir_v2, ca
8383
assert "Average Response Time" in output
8484

8585
def test_human_output_includes_verdict(self, temp_test_dir, temp_test_dir_v2, capsys):
86-
compare_reports(temp_test_dir, temp_test_dir_v2, as_json=False, show_verdict=True)
86+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="text", show_verdict=True)
8787

8888
captured = capsys.readouterr()
8989
output = captured.out
@@ -94,7 +94,7 @@ def test_human_output_includes_verdict(self, temp_test_dir, temp_test_dir_v2, ca
9494
assert "better" in output or "worse" in output or "same" in output
9595

9696
def test_human_output_no_verdict(self, temp_test_dir, temp_test_dir_v2, capsys):
97-
compare_reports(temp_test_dir, temp_test_dir_v2, as_json=False, show_verdict=False)
97+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="text", show_verdict=False)
9898

9999
captured = capsys.readouterr()
100100
output = captured.out
@@ -105,7 +105,7 @@ def test_human_output_no_verdict(self, temp_test_dir, temp_test_dir_v2, capsys):
105105
assert "Verdict" not in header_line
106106

107107
def test_human_output_colorize(self, temp_test_dir, temp_test_dir_v2, capsys):
108-
compare_reports(temp_test_dir, temp_test_dir_v2, as_json=False, colorize=True)
108+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="text", colorize=True)
109109

110110
captured = capsys.readouterr()
111111
output = captured.out
@@ -119,7 +119,7 @@ class TestCompareReportsEdgeCases:
119119

120120
def test_compare_same_report(self, temp_test_dir, capsys):
121121
"""Comparing a report to itself should show no changes."""
122-
compare_reports(temp_test_dir, temp_test_dir, as_json=True)
122+
compare_reports(temp_test_dir, temp_test_dir, output_format="json")
123123

124124
captured = capsys.readouterr()
125125
data = json.loads(captured.out)
@@ -141,7 +141,7 @@ def test_compare_with_missing_endpoint(self, sample_csv_content, sample_csv_cont
141141
base_path.write_text(base_csv)
142142
curr_path.write_text(sample_csv_content_v2)
143143

144-
compare_reports(Path(base_dir), Path(curr_dir), as_json=True)
144+
compare_reports(Path(base_dir), Path(curr_dir), output_format="json")
145145

146146
captured = capsys.readouterr()
147147
data = json.loads(captured.out)
@@ -164,7 +164,7 @@ def test_compare_with_new_endpoint(self, sample_csv_content, sample_csv_content_
164164
base_path.write_text(sample_csv_content)
165165
curr_path.write_text(curr_csv)
166166

167-
compare_reports(Path(base_dir), Path(curr_dir), as_json=True)
167+
compare_reports(Path(base_dir), Path(curr_dir), output_format="json")
168168

169169
captured = capsys.readouterr()
170170
data = json.loads(captured.out)
@@ -195,7 +195,7 @@ def test_json_includes_html_features(self, temp_dir_with_html, capsys):
195195
if html_file.name != "htmlpublisher-wrapper.html":
196196
shutil.copy(html_file, other / html_file.name)
197197

198-
compare_reports(temp_dir_with_html, other, as_json=True)
198+
compare_reports(temp_dir_with_html, other, output_format="json")
199199

200200
captured = capsys.readouterr()
201201
data = json.loads(captured.out)
@@ -218,7 +218,7 @@ def test_human_output_includes_html_section(self, temp_dir_with_html, capsys):
218218
if html_file.name != "htmlpublisher-wrapper.html":
219219
shutil.copy(html_file, other / html_file.name)
220220

221-
compare_reports(temp_dir_with_html, other, as_json=False)
221+
compare_reports(temp_dir_with_html, other, output_format="text")
222222

223223
captured = capsys.readouterr()
224224
output = captured.out
@@ -238,7 +238,7 @@ def test_compare_real_reports(self, real_test_runs_path, capsys):
238238
if not base.exists() or not curr.exists():
239239
pytest.skip("Real test data not available")
240240

241-
result = compare_reports(base, curr, as_json=True)
241+
result = compare_reports(base, curr, output_format="json")
242242
assert result == 0
243243

244244
captured = capsys.readouterr()

tests/test_markdown_output.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_verdict_to_emoji_none(self):
3131

3232
def test_markdown_output_structure(self, temp_test_dir, temp_test_dir_v2, capsys):
3333
"""Test that markdown output has correct structure."""
34-
result = compare_reports(temp_test_dir, temp_test_dir_v2, as_markdown=True)
34+
result = compare_reports(temp_test_dir, temp_test_dir_v2, output_format="markdown")
3535
assert result == 0
3636

3737
captured = capsys.readouterr()
@@ -48,7 +48,7 @@ def test_markdown_output_structure(self, temp_test_dir, temp_test_dir_v2, capsys
4848

4949
def test_markdown_output_includes_metrics(self, temp_test_dir, temp_test_dir_v2, capsys):
5050
"""Test that markdown output includes all expected metrics."""
51-
compare_reports(temp_test_dir, temp_test_dir_v2, as_markdown=True)
51+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="markdown")
5252

5353
captured = capsys.readouterr()
5454
output = captured.out
@@ -61,7 +61,7 @@ def test_markdown_output_includes_metrics(self, temp_test_dir, temp_test_dir_v2,
6161

6262
def test_markdown_output_includes_emojis(self, temp_test_dir, temp_test_dir_v2, capsys):
6363
"""Test that markdown output includes emoji indicators."""
64-
compare_reports(temp_test_dir, temp_test_dir_v2, as_markdown=True, show_verdict=True)
64+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="markdown", show_verdict=True)
6565

6666
captured = capsys.readouterr()
6767
output = captured.out
@@ -71,7 +71,7 @@ def test_markdown_output_includes_emojis(self, temp_test_dir, temp_test_dir_v2,
7171

7272
def test_markdown_output_no_verdict(self, temp_test_dir, temp_test_dir_v2, capsys):
7373
"""Test markdown output without verdict column."""
74-
compare_reports(temp_test_dir, temp_test_dir_v2, as_markdown=True, show_verdict=False)
74+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="markdown", show_verdict=False)
7575

7676
captured = capsys.readouterr()
7777
output = captured.out
@@ -85,7 +85,7 @@ def test_markdown_output_no_verdict(self, temp_test_dir, temp_test_dir_v2, capsy
8585

8686
def test_markdown_output_no_color_codes(self, temp_test_dir, temp_test_dir_v2, capsys):
8787
"""Test that markdown output does not contain ANSI color codes."""
88-
compare_reports(temp_test_dir, temp_test_dir_v2, as_markdown=True)
88+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="markdown")
8989

9090
captured = capsys.readouterr()
9191
output = captured.out
@@ -97,7 +97,7 @@ def test_markdown_output_no_color_codes(self, temp_test_dir, temp_test_dir_v2, c
9797

9898
def test_markdown_table_format(self, temp_test_dir, temp_test_dir_v2, capsys):
9999
"""Test that markdown tables are properly formatted."""
100-
compare_reports(temp_test_dir, temp_test_dir_v2, as_markdown=True, show_verdict=True)
100+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="markdown", show_verdict=True)
101101

102102
captured = capsys.readouterr()
103103
output = captured.out
@@ -130,7 +130,7 @@ def test_markdown_with_html_features(self, temp_dir_with_html, capsys):
130130
if html_file.name != "htmlpublisher-wrapper.html":
131131
shutil.copy(html_file, other / html_file.name)
132132

133-
compare_reports(temp_dir_with_html, other, as_markdown=True)
133+
compare_reports(temp_dir_with_html, other, output_format="markdown")
134134

135135
captured = capsys.readouterr()
136136
output = captured.out
@@ -141,7 +141,7 @@ def test_markdown_with_html_features(self, temp_dir_with_html, capsys):
141141

142142
def test_markdown_output_values(self, temp_test_dir, temp_test_dir_v2, capsys):
143143
"""Test that markdown output contains correct values."""
144-
compare_reports(temp_test_dir, temp_test_dir_v2, as_markdown=True)
144+
compare_reports(temp_test_dir, temp_test_dir_v2, output_format="markdown")
145145

146146
captured = capsys.readouterr()
147147
output = captured.out
@@ -156,7 +156,7 @@ class TestMarkdownCompatibility:
156156

157157
def test_json_still_works(self, temp_test_dir, temp_test_dir_v2, capsys):
158158
"""Test that JSON output is not affected by markdown changes."""
159-
result = compare_reports(temp_test_dir, temp_test_dir_v2, as_json=True)
159+
result = compare_reports(temp_test_dir, temp_test_dir_v2, output_format="json")
160160
assert result == 0
161161

162162
captured = capsys.readouterr()
@@ -165,7 +165,7 @@ def test_json_still_works(self, temp_test_dir, temp_test_dir_v2, capsys):
165165

166166
def test_normal_output_still_works(self, temp_test_dir, temp_test_dir_v2, capsys):
167167
"""Test that normal human-readable output still works."""
168-
result = compare_reports(temp_test_dir, temp_test_dir_v2, as_json=False, as_markdown=False)
168+
result = compare_reports(temp_test_dir, temp_test_dir_v2, output_format="text")
169169
assert result == 0
170170

171171
captured = capsys.readouterr()
@@ -177,7 +177,7 @@ def test_normal_output_still_works(self, temp_test_dir, temp_test_dir_v2, capsys
177177

178178
def test_color_output_still_works(self, temp_test_dir, temp_test_dir_v2, capsys):
179179
"""Test that colorized output still works."""
180-
result = compare_reports(temp_test_dir, temp_test_dir_v2, colorize=True, as_markdown=False)
180+
result = compare_reports(temp_test_dir, temp_test_dir_v2, output_format="text", colorize=True)
181181
assert result == 0
182182

183183
captured = capsys.readouterr()

tests/test_zip_support.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_compare_zip_to_zip(self, sample_csv_content, sample_csv_content_v2, cap
112112
with zipfile.ZipFile(curr_zip, "w") as zf:
113113
zf.writestr("report.csv", sample_csv_content_v2)
114114

115-
result = compare_reports(base_zip, curr_zip, as_json=True)
115+
result = compare_reports(base_zip, curr_zip, output_format="json")
116116
assert result == 0
117117

118118
captured = capsys.readouterr()
@@ -126,7 +126,7 @@ def test_compare_zip_to_directory(self, sample_csv_content, temp_test_dir_v2, ca
126126
with zipfile.ZipFile(base_zip, "w") as zf:
127127
zf.writestr("report.csv", sample_csv_content)
128128

129-
result = compare_reports(base_zip, temp_test_dir_v2, as_json=True)
129+
result = compare_reports(base_zip, temp_test_dir_v2, output_format="json")
130130
assert result == 0
131131

132132
def test_compare_directory_to_zip(self, temp_test_dir, sample_csv_content_v2, capsys):
@@ -137,7 +137,7 @@ def test_compare_directory_to_zip(self, temp_test_dir, sample_csv_content_v2, ca
137137
with zipfile.ZipFile(curr_zip, "w") as zf:
138138
zf.writestr("report.csv", sample_csv_content_v2)
139139

140-
result = compare_reports(temp_test_dir, curr_zip, as_json=True)
140+
result = compare_reports(temp_test_dir, curr_zip, output_format="json")
141141
assert result == 0
142142

143143
def test_zip_with_nested_directory_structure(self, sample_csv_content, sample_csv_content_v2, capsys):
@@ -152,7 +152,7 @@ def test_zip_with_nested_directory_structure(self, sample_csv_content, sample_cs
152152
with zipfile.ZipFile(curr_zip, "w") as zf:
153153
zf.writestr("HTML-Report-200/report.csv", sample_csv_content_v2)
154154

155-
result = compare_reports(base_zip, curr_zip, as_json=True)
155+
result = compare_reports(base_zip, curr_zip, output_format="json")
156156
assert result == 0
157157

158158
def test_zip_with_html_files(self, sample_csv_content, sample_html_template_args, capsys):
@@ -169,7 +169,7 @@ def test_zip_with_html_files(self, sample_csv_content, sample_html_template_args
169169
zf.writestr("report.csv", sample_csv_content)
170170
zf.writestr("feature_test.html", sample_html_template_args)
171171

172-
result = compare_reports(base_zip, curr_zip, as_json=True)
172+
result = compare_reports(base_zip, curr_zip, output_format="json")
173173
assert result == 0
174174

175175
captured = capsys.readouterr()

0 commit comments

Comments
 (0)