Skip to content

Commit d40b13f

Browse files
committed
Rename retry flake-detection to the detect-flake command
1 parent fcba93c commit d40b13f

File tree

7 files changed

+54
-41
lines changed

7 files changed

+54
-41
lines changed

launchable/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from launchable.app import Application
1111

1212
from .commands.compare import compare
13+
from .commands.detect_flakes import detect_flakes
1314
from .commands.inspect import inspect
1415
from .commands.record import record
15-
from .commands.retry import retry
1616
from .commands.split_subset import split_subset
1717
from .commands.stats import stats
1818
from .commands.subset import subset
@@ -92,7 +92,7 @@ def main(ctx, log_level, plugin_dir, dry_run, skip_cert_verification):
9292
main.add_command(inspect)
9393
main.add_command(stats)
9494
main.add_command(compare)
95-
main.add_command(retry)
95+
main.add_command(detect_flakes, "detect-flakes")
9696

9797
if __name__ == '__main__':
9898
main()

launchable/commands/retry/flake_detection.py renamed to launchable/commands/detect_flakes.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from launchable.utils.launchable_client import LaunchableClient
1212
from launchable.utils.tracking import Tracking, TrackingClient
1313

14-
from ...utils.commands import Command
14+
from ..utils.commands import Command
1515

1616

1717
@click.group(help="Early flake detection")
@@ -23,14 +23,16 @@
2323
required=True
2424
)
2525
@click.option(
26-
'--confidence',
27-
help='Confidence level for flake detection',
26+
'--retry-threshold',
27+
'retry_threshold',
28+
help='Throughness of how "flake" is detected',
2829
type=click.Choice(['low', 'medium', 'high'], case_sensitive=False),
30+
default='medium',
2931
required=True,
3032
)
3133
@click.pass_context
32-
def flake_detection(ctx, confidence, session):
33-
tracking_client = TrackingClient(Command.FLAKE_DETECTION, app=ctx.obj)
34+
def detect_flakes(ctx, retry_threshold, session):
35+
tracking_client = TrackingClient(Command.DETECT_FLAKE, app=ctx.obj)
3436
client = LaunchableClient(app=ctx.obj, tracking_client=tracking_client, test_runner=ctx.invoked_subcommand)
3537
session_id = None
3638
try:
@@ -64,9 +66,9 @@ def run(self):
6466
try:
6567
res = client.request(
6668
"get",
67-
"retry/flake-detection",
69+
"detect-flake",
6870
params={
69-
"confidence": confidence.upper(),
71+
"confidence": retry_threshold.upper(),
7072
"session-id": os.path.basename(session_id),
7173
"test-runner": ctx.invoked_subcommand})
7274
res.raise_for_status()

launchable/commands/retry/__init__.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

launchable/test_runners/launchable.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import click
77

8+
from launchable.commands.detect_flakes import detect_flakes as detect_flakes_cmd
89
from launchable.commands.record.tests import tests as record_tests_cmd
9-
from launchable.commands.retry.flake_detection import flake_detection as flake_detection_cmd
1010
from launchable.commands.split_subset import split_subset as split_subset_cmd
1111
from launchable.commands.subset import subset as subset_cmd
1212
from launchable.testpath import unparse_test_path
@@ -46,7 +46,7 @@ def subset(f):
4646

4747

4848
def flake_detection(f):
49-
return wrap(f, flake_detection_cmd)
49+
return wrap(f, detect_flakes_cmd)
5050

5151

5252
def split_subset(f):
@@ -184,8 +184,8 @@ def __init__(
184184
self._formatter = formatter
185185
self._separator = seperator
186186

187-
def flake_detection(self):
188-
def flake_detection(client):
187+
def detect_flakes(self):
188+
def detect_flakes(client):
189189
if self._formatter:
190190
client.formatter = self._formatter
191191

@@ -194,4 +194,4 @@ def flake_detection(client):
194194

195195
client.run()
196196

197-
return wrap(flake_detection, flake_detection_cmd, self.cmdname)
197+
return wrap(detect_flakes, detect_flakes_cmd, self.cmdname)

launchable/test_runners/rspec.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
subset = launchable.CommonSubsetImpls(__name__).scan_files('*_spec.rb')
44
split_subset = launchable.CommonSplitSubsetImpls(__name__).split_subset()
55
record_tests = launchable.CommonRecordTestImpls(__name__).report_files()
6+
launchable.CommonFlakeDetectionImpls(__name__).flake_detection()

launchable/utils/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Command(Enum):
88
RECORD_SESSION = 'RECORD_SESSION'
99
SUBSET = 'SUBSET'
1010
COMMIT = 'COMMIT'
11-
FLAKE_DETECTION = 'FLAKE_DETECTION'
11+
DETECT_FLAKE = 'DETECT_FLAKE'
1212

1313
def display_name(self):
1414
return self.value.lower().replace('_', ' ')
Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from tests.cli_test_case import CliTestCase
88

99

10-
class FlakeDetectionTest(CliTestCase):
10+
class DetectFlakeTest(CliTestCase):
1111
@responses.activate
1212
@mock.patch.dict(os.environ, {"LAUNCHABLE_TOKEN": CliTestCase.launchable_token})
1313
def test_flake_detection_success(self):
@@ -19,16 +19,15 @@ def test_flake_detection_success(self):
1919
}
2020
responses.add(
2121
responses.GET,
22-
f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/retry/flake-detection",
22+
f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/detect-flake",
2323
json=mock_json_response,
2424
status=200,
2525
)
2626
result = self.cli(
27-
"retry",
28-
"flake-detection",
27+
"detect-flakes",
2928
"--session",
3029
self.session,
31-
"--confidence",
30+
"--retry-threshold",
3231
"high",
3332
"file",
3433
mix_stderr=False,
@@ -37,22 +36,47 @@ def test_flake_detection_success(self):
3736
self.assertIn("test_flaky_1.py", result.stdout)
3837
self.assertIn("test_flaky_2.py", result.stdout)
3938

39+
@responses.activate
40+
@mock.patch.dict(os.environ, {"LAUNCHABLE_TOKEN": CliTestCase.launchable_token})
41+
def test_flake_detection_without_retry_threshold_success(self):
42+
mock_json_response = {
43+
"testPaths": [
44+
[{"type": "file", "name": "test_flaky_1.py"}],
45+
[{"type": "file", "name": "test_flaky_2.py"}],
46+
]
47+
}
48+
responses.add(
49+
responses.GET,
50+
f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/detect-flake",
51+
json=mock_json_response,
52+
status=200,
53+
)
54+
result = self.cli(
55+
"detect-flakes",
56+
"--session",
57+
self.session,
58+
"file",
59+
mix_stderr=False,
60+
)
61+
self.assert_success(result)
62+
self.assertIn("test_flaky_1.py", result.stdout)
63+
self.assertIn("test_flaky_2.py", result.stdout)
64+
4065
@responses.activate
4166
@mock.patch.dict(os.environ, {"LAUNCHABLE_TOKEN": CliTestCase.launchable_token})
4267
def test_flake_detection_no_flakes(self):
4368
mock_json_response = {"testPaths": []}
4469
responses.add(
4570
responses.GET,
46-
f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/retry/flake-detection",
71+
f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/detect-flake",
4772
json=mock_json_response,
4873
status=200,
4974
)
5075
result = self.cli(
51-
"retry",
52-
"flake-detection",
76+
"detect-flakes",
5377
"--session",
5478
self.session,
55-
"--confidence",
79+
"--retry-threshold",
5680
"low",
5781
"file",
5882
mix_stderr=False,
@@ -65,15 +89,14 @@ def test_flake_detection_no_flakes(self):
6589
def test_flake_detection_api_error(self):
6690
responses.add(
6791
responses.GET,
68-
f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/retry/flake-detection",
92+
f"{get_base_url()}/intake/organizations/{self.organization}/workspaces/{self.workspace}/detect-flake",
6993
status=500,
7094
)
7195
result = self.cli(
72-
"retry",
73-
"flake-detection",
96+
"detect-flakes",
7497
"--session",
7598
self.session,
76-
"--confidence",
99+
"--retry-threshold",
77100
"medium",
78101
"file",
79102
mix_stderr=False,

0 commit comments

Comments
 (0)