2

Please consider the following batch script:

call <somepath>/py.test.exe <someotherpath>/tests
if %errorlevel%==0 (
    echo Tests successful.
) else (
    echo Tests failed.
)

However, even when pytest tests fail, I get Tests successful. What's going on?

Aviv Cohn
  • 15,543
  • 25
  • 68
  • 131
  • Maybe a duplicate: https://stackoverflow.com/questions/24866477/if-call-exit-and-errorlevel-in-a-bat – VPfB May 18 '19 at 15:23
  • First, in a batch file there is no need to use command __CALL__ to run an executable and halt batch file execution until the executable terminated itself. The command __CALL__ is needed mainly for calling another batch file from within a batch file. So I suggest first to remove `call` from first line. – Mofi May 19 '19 at 08:57
  • Next I recommend to open a command prompt window and run `if /?`. The output help explains on first page how to evaluate the exit code of a command or executable by using the syntax `if [not] errorlevel number command` which works also inside command blocks starting with `(` and ending with matching `)`. So use for second line `if errorlevel 1 (echo Tests failed.) else echo Tests successful.` See also [Single line with multiple commands using Windows batch file](https://stackoverflow.com/a/25344009/3074564) for an alternate method to evaluate exit code of an application or command. – Mofi May 19 '19 at 09:01

0 Answers0