@@ -217,8 +217,10 @@ def foo():
217217
218218
219219def _run_formatting_test (source_filename : str , should_content_change : bool ):
220- if shutil .which ("ruff" ) is None :
221- pytest .skip ("ruff is not installed, skipping." )
220+ try :
221+ import ruff # type: ignore
222+ except ImportError :
223+ pytest .skip ("ruff is not installed" )
222224 with tempfile .TemporaryDirectory () as test_dir_str :
223225 test_dir = Path (test_dir_str )
224226 this_file = Path (__file__ ).resolve ()
@@ -269,19 +271,12 @@ def _run_formatting_test(source_filename: str, should_content_change: bool):
269271 else :
270272 assert content == original , f"Expected content to remain unchanged for { source_filename } "
271273
272- def _ruff_or_black_installed () -> bool :
273- return shutil .which ("black" ) is not None or shutil .which ("ruff" ) is not None
274-
275274
276275def test_formatting_file_with_many_diffs ():
277276 """Test that files with many formatting errors are skipped (content unchanged)."""
278- if not _ruff_or_black_installed ():
279- pytest .skip ("Neither black nor ruff is installed, skipping formatting tests." )
280277 _run_formatting_test ("many_formatting_errors.py" , should_content_change = False )
281278
282279
283280def test_formatting_file_with_few_diffs ():
284281 """Test that files with few formatting errors are formatted (content changed)."""
285- if not _ruff_or_black_installed ():
286- pytest .skip ("Neither black nor ruff is installed, skipping formatting tests." )
287282 _run_formatting_test ("few_formatting_errors.py" , should_content_change = True )
0 commit comments