Как упомянул @AnsgarWiechers, вы должны явно проверять наличие $LASTEXITCODE -eq 0
вместо $true
.
Вот простой пример для вашего примера:
test.py
content:
import sys
print(f'Testing for {sys.argv}')
assert sys.argv[1] == 'Success'
test.ps1
содержание:
py test.py Fail # or Success
if ($LASTEXITCODE -eq 0) {
Write-Output "Python script ran successfully"
}
else {
Write-Output "Python script failed"
}
Результаты:
Testing for ['test.py', 'Success']
Python script ran successfully
# ...
Testing for ['test.py', 'Fail']
Traceback (most recent call last):
File "test.py", line 5, in <module>
assert sys.argv[1] == 'Success'
AssertionError
Python script failed