#!/bin/bash

set -e

# run pytest with args set
echo 'Running integration tests...'
patience --services http://$MONEYHUB_HOST:$MONEYHUB_PORT/hello
python3 tests/integration/utils/drop_fks.py
COVERAGE_ARGS='--cov-report=term --cov=moneyhub --junitxml=pyunit.xml --cov-config=setup.cfg'

PYTHONDONTWRITEBYTECODE=1 python -m pytest tests/integration tests/functional/ -s -p no:cacheprovider $COVERAGE_ARGS
PYTEST_EXIT_CODE=$?

# Check if pytest was successful
if [ $PYTEST_EXIT_CODE -eq 0 ]; then
  echo 'Writing coverage report...'
  coverage xml --rcfile=setup.cfg
  echo 'Done!'
else
    echo 'Pytest failed. Skipping coverage report.'
fi

# Exit with the pytest exit code
exit $PYTEST_EXIT_CODE
