Skip to content

Commit 05def83

Browse files
authored
fix(test-tests): prevent race condition in gentest tests w/xdist (#2009)
* fix(gentest): capture ruff stderr in format error messages Include ruff's stderr output in exceptions when formatting fails, enabling diagnosis of the root cause in CI failures. * fix(gentest): disable ruff cache to prevent parallel test failures Add --no-cache flag to ruff invocation to prevent potential race conditions when pytest-xdist runs tests with multiple workers sharing the same .ruff_cache directory.
1 parent f391a0c commit 05def83

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

packages/testing/src/execution_testing/cli/gentest/source_code_generator.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,24 @@ def format_code(code: str) -> str:
8484
# Call ruff to format the file
8585
config_path = AppConfig().ROOT_DIR.parent / "pyproject.toml"
8686

87-
try:
88-
subprocess.run(
89-
[
90-
str(formatter_path),
91-
"format",
92-
str(input_file_path),
93-
"--quiet",
94-
"--config",
95-
str(config_path),
96-
],
97-
check=True,
98-
)
99-
except subprocess.CalledProcessError as e:
87+
result = subprocess.run(
88+
[
89+
str(formatter_path),
90+
"format",
91+
str(input_file_path),
92+
"--quiet",
93+
"--no-cache",
94+
"--config",
95+
str(config_path),
96+
],
97+
capture_output=True,
98+
text=True,
99+
)
100+
if result.returncode != 0:
100101
raise Exception(
101-
f"Error formatting code using formatter '{formatter_path}'"
102-
) from e
102+
f"Error formatting code using formatter '{formatter_path}': "
103+
f"{result.stderr}"
104+
)
103105

104106
# Return the formatted source code
105107
return input_file_path.read_text()

0 commit comments

Comments
 (0)