$env:PYTHONPATH = "C:\Users\simon\wecom_it_smart_desk\backend"
$env:PYTHONDONTWRITEBYTECODE = "1"
Set-Location "C:\Users\simon\wecom_it_smart_desk\backend"

# Remove __pycache__ directories
Get-ChildItem -Recurse -Directory -Filter "__pycache__" | Remove-Item -Recurse -Force

# Run pytest
$output = & "C:\Users\simon\.workbuddy\binaries\python\envs\default\Scripts\python.exe" -B -m pytest tests/ -v --tb=short -x --cache-clear 2>&1 | Out-String

# Write results to file
$output | Out-File -FilePath "C:\Users\simon\wecom_it_smart_desk\backend\test_results.txt" -Encoding utf8
"EXIT_CODE=$LASTEXITCODE" | Out-File -FilePath "C:\Users\simon\wecom_it_smart_desk\backend\test_results.txt" -Append -Encoding utf8
