0

I have following structure: Koholo job that calling python script, the script returns error code (1 - failed, 0 - passed) as it ends. Koholo wait for the error code to continue to next job step (next scrips). Now instead of python script I'm running pytest scrips (with command: python -m pytest test_name) but pytest is not returning error code, so the Kohola job timeouts. Please let me know if there is a way that pytest will return error code as it finish's?

1
  • Seems like you could do something like this answer. Commented Jul 11, 2021 at 0:34

2 Answers 2

1

example you can pass any pytest argument that you normaly pass in the cli, i am just using the markers as an example

import sys
import pytest

results = pytest.main(["-m", "my_marker"])
sys.exit(results)

if you want more details https://docs.pytest.org/en/7.1.x/reference/exit-codes.html

Sign up to request clarification or add additional context in comments.

Comments

0

when pytest finish it calls pytest_sessionfinish(session, exitstatus) method. try to add sys.exit(exitstatus) to this method.

import sys


def pytest_sessionfinish(session, exitstatus):
    """ whole test run finishes. """
    sys.exit(exitstatus)

also you can check by running this script to check the exit code

start /wait  python -m pytest test_name
echo %errorlevel%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.