Skip to content

Commit 781367c

Browse files
Fix xdist issue with multiple approaches
- Use PYTEST_DISABLE_PLUGIN_AUTOLOAD environment variable (recommended in CLAUDE.md) - Use -p no:xdist flag to explicitly disable the plugin - Add --no-cov to avoid coverage plugin issues - Add test-stdio-simple.ps1 to try different methods of disabling xdist
1 parent 154ef9c commit 781367c

File tree

4 files changed

+83
-6
lines changed

4 files changed

+83
-6
lines changed

scripts/windows-debug/test-stdio-flakiness-200-runs.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Write-Host "Running test_stdio_context_manager_exiting 200 times to detect flaki
66
Write-Host "Test: tests/client/test_stdio.py::test_stdio_context_manager_exiting" -ForegroundColor Yellow
77
Write-Host ""
88

9+
# Disable pytest plugin autoload to avoid xdist issues
10+
$env:PYTEST_DISABLE_PLUGIN_AUTOLOAD = ""
11+
912
$startTime = Get-Date
1013
$count = 0
1114
$failures = 0
@@ -14,7 +17,10 @@ $failedRuns = @()
1417
for ($i = 1; $i -le 200; $i++) {
1518
Write-Host "Run $i of 200..." -NoNewline
1619

17-
$output = uv run --frozen pytest tests/client/test_stdio.py::test_stdio_context_manager_exiting -xvs -n 0 2>&1
20+
$output = & {
21+
$env:PYTEST_DISABLE_PLUGIN_AUTOLOAD = ""
22+
uv run --frozen pytest tests/client/test_stdio.py::test_stdio_context_manager_exiting -xvs --no-cov -p no:xdist 2>&1
23+
}
1824
$exitCode = $LASTEXITCODE
1925

2026
if ($exitCode -ne 0) {
@@ -41,4 +47,7 @@ if ($failures -gt 0) {
4147
Write-Host "Failed on runs: $($failedRuns -join ', ')" -ForegroundColor Red
4248
}
4349
Write-Host "Duration: $($duration.ToString())"
44-
Write-Host "Failure rate: $([math]::Round(($failures / 200) * 100, 2))%"
50+
Write-Host "Failure rate: $([math]::Round(($failures / 200) * 100, 2))%"
51+
52+
# Clean up environment variable
53+
Remove-Item Env:PYTEST_DISABLE_PLUGIN_AUTOLOAD -ErrorAction SilentlyContinue

scripts/windows-debug/test-stdio-flakiness-until-failure.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ Write-Host "Test: tests/client/test_stdio.py::test_stdio_context_manager_exiting
77
Write-Host "Press Ctrl+C to stop" -ForegroundColor Gray
88
Write-Host ""
99

10+
# Disable pytest plugin autoload to avoid xdist issues
11+
$env:PYTEST_DISABLE_PLUGIN_AUTOLOAD = ""
12+
1013
$startTime = Get-Date
1114
$i = 0
1215

1316
while ($true) {
1417
$i++
1518
Write-Host "Run $i..." -NoNewline
1619

17-
$output = uv run --frozen pytest tests/client/test_stdio.py::test_stdio_context_manager_exiting -xvs -n 0 2>&1
20+
$output = & {
21+
$env:PYTEST_DISABLE_PLUGIN_AUTOLOAD = ""
22+
uv run --frozen pytest tests/client/test_stdio.py::test_stdio_context_manager_exiting -xvs --no-cov -p no:xdist 2>&1
23+
}
1824
$exitCode = $LASTEXITCODE
1925

2026
if ($exitCode -ne 0) {
@@ -39,4 +45,7 @@ while ($true) {
3945
}
4046

4147
Write-Host ""
42-
Write-Host "Exiting after failure detection." -ForegroundColor Cyan
48+
Write-Host "Exiting after failure detection." -ForegroundColor Cyan
49+
50+
# Clean up environment variable
51+
Remove-Item Env:PYTEST_DISABLE_PLUGIN_AUTOLOAD -ErrorAction SilentlyContinue
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env pwsh
2+
# Simple script to run the test without xdist
3+
# Usage: .\test-stdio-simple.ps1
4+
5+
Write-Host "Running test_stdio_context_manager_exiting with xdist disabled..." -ForegroundColor Cyan
6+
Write-Host ""
7+
8+
# Method 1: Using environment variable (recommended in CLAUDE.md)
9+
Write-Host "Method 1: Using PYTEST_DISABLE_PLUGIN_AUTOLOAD environment variable" -ForegroundColor Yellow
10+
$env:PYTEST_DISABLE_PLUGIN_AUTOLOAD = ""
11+
uv run --frozen pytest tests/client/test_stdio.py::test_stdio_context_manager_exiting -xvs
12+
$exitCode1 = $LASTEXITCODE
13+
Remove-Item Env:PYTEST_DISABLE_PLUGIN_AUTOLOAD -ErrorAction SilentlyContinue
14+
15+
if ($exitCode1 -eq 0) {
16+
Write-Host "Method 1: PASSED" -ForegroundColor Green
17+
} else {
18+
Write-Host "Method 1: FAILED with exit code $exitCode1" -ForegroundColor Red
19+
}
20+
21+
Write-Host ""
22+
23+
# Method 2: Using -p no:xdist to disable the plugin
24+
Write-Host "Method 2: Using -p no:xdist flag" -ForegroundColor Yellow
25+
uv run --frozen pytest tests/client/test_stdio.py::test_stdio_context_manager_exiting -xvs -p no:xdist
26+
$exitCode2 = $LASTEXITCODE
27+
28+
if ($exitCode2 -eq 0) {
29+
Write-Host "Method 2: PASSED" -ForegroundColor Green
30+
} else {
31+
Write-Host "Method 2: FAILED with exit code $exitCode2" -ForegroundColor Red
32+
}
33+
34+
Write-Host ""
35+
36+
# Method 3: Override addopts from pyproject.toml
37+
Write-Host "Method 3: Overriding pytest addopts" -ForegroundColor Yellow
38+
uv run --frozen pytest tests/client/test_stdio.py::test_stdio_context_manager_exiting -xvs -o addopts=""
39+
$exitCode3 = $LASTEXITCODE
40+
41+
if ($exitCode3 -eq 0) {
42+
Write-Host "Method 3: PASSED" -ForegroundColor Green
43+
} else {
44+
Write-Host "Method 3: FAILED with exit code $exitCode3" -ForegroundColor Red
45+
}
46+
47+
Write-Host ""
48+
Write-Host "========== SUMMARY ==========" -ForegroundColor Cyan
49+
if ($exitCode1 -eq 0 -or $exitCode2 -eq 0 -or $exitCode3 -eq 0) {
50+
Write-Host "At least one method succeeded!" -ForegroundColor Green
51+
Write-Host "Use the successful method in your testing."
52+
} else {
53+
Write-Host "All methods failed. The test may have a different issue." -ForegroundColor Red
54+
}

scripts/windows-debug/test-stdio-verbose-debug.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@ Write-Host ""
88
# Set environment variables for debugging
99
$env:PYTHONFAULTHANDLER = "1"
1010
$env:PYTEST_CURRENT_TEST = "1"
11+
$env:PYTEST_DISABLE_PLUGIN_AUTOLOAD = ""
1112

1213
Write-Host "Environment variables set:" -ForegroundColor Yellow
1314
Write-Host " PYTHONFAULTHANDLER = 1 (enables Python fault handler)"
15+
Write-Host " PYTEST_DISABLE_PLUGIN_AUTOLOAD = '' (disables pytest plugin autoload)"
1416
Write-Host ""
1517

1618
Write-Host "Running test with maximum verbosity..." -ForegroundColor Cyan
1719
Write-Host ""
1820

1921
# Run the test with all debugging options
22+
$env:PYTEST_DISABLE_PLUGIN_AUTOLOAD = ""
2023
uv run --frozen pytest `
2124
tests/client/test_stdio.py::test_stdio_context_manager_exiting `
2225
-xvs `
23-
-n 0 `
26+
--no-cov `
27+
-p no:xdist `
2428
--log-cli-level=DEBUG `
2529
--log-cli-format="%(asctime)s [%(levelname)s] %(name)s: %(message)s" `
2630
--capture=no `
@@ -38,4 +42,5 @@ if ($exitCode -eq 0) {
3842

3943
# Clean up environment variables
4044
Remove-Item Env:PYTHONFAULTHANDLER -ErrorAction SilentlyContinue
41-
Remove-Item Env:PYTEST_CURRENT_TEST -ErrorAction SilentlyContinue
45+
Remove-Item Env:PYTEST_CURRENT_TEST -ErrorAction SilentlyContinue
46+
Remove-Item Env:PYTEST_DISABLE_PLUGIN_AUTOLOAD -ErrorAction SilentlyContinue

0 commit comments

Comments
 (0)