pytest.main() will return its exit code — which is an ExitCode enum, starting with pytest 5.0.0. If a test has failed, ExitCode.TESTS_FAILED will be returned; if all tests pass, ExitCode.OK will be returned.
Incidentally, the integer values of these enums are actually the exit codes used if run from the terminal. And here's the source of site-packages/pytest/__main__.py, which is executed if python -m pytest is used to invoke tests:
import pytest
if __name__ == "__main__":
raise SystemExit(pytest.main())
The py.test (or pytest) entry point script is largely the same
import re
import sys
from pytest import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
exit(pytest.main())