Skip to content

Commit

Permalink
Only run tests if compilation succeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Jan 21, 2025
1 parent 4052843 commit dee0d9e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions crates/red_knot_python_semantic/mdtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def _run_cargo_test(self, message_format: Literal["human", "json"]) -> str:

def _recompile_tests(
self, status_message: str, message_on_success: bool = True
) -> None:
) -> bool:
with self.console.status(status_message):
# Run it with 'human' format in case there are errors:
try:
self._run_cargo_test(message_format="human")
except subprocess.CalledProcessError as e:
print(e.output)
return
return False

# Run it again with 'json' format to find the mdtest executable:
json_output = self._run_cargo_test(message_format="json")
Expand All @@ -65,6 +65,7 @@ def _recompile_tests(

if message_on_success:
self.console.print("[dim]Tests compiled successfully[/dim]")
return True

def _get_executable_path_from_json(self, json_output: str) -> None:
for json_line in json_output.splitlines():
Expand Down Expand Up @@ -135,9 +136,6 @@ def _run_mdtests_for_file(self, markdown_file: Path) -> None:

print(line)

def _run_all_mdtests(self) -> None:
self._run_mdtest()

def watch(self) -> Never:
self._recompile_tests("Compiling tests...", message_on_success=False)
self.console.print("[dim]Ready to watch for changes...[/dim]")
Expand Down Expand Up @@ -176,8 +174,8 @@ def watch(self) -> Never:
changed_md_files.add(relative_path)

if rust_code_has_changed:
self._recompile_tests("Rust code has changed, recompiling tests...")
self._run_all_mdtests()
if self._recompile_tests("Rust code has changed, recompiling tests..."):
self._run_mdtest()
elif new_md_files:
files = " ".join(file.as_posix() for file in new_md_files)
self._recompile_tests(
Expand Down

0 comments on commit dee0d9e

Please sign in to comment.