Commit 20a89242 authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Refactor test_py_project to support in-module tests

parent afcd1b74
Loading
Loading
Loading
Loading
+64 −48
Original line number Diff line number Diff line
@@ -339,40 +339,7 @@ test_py_project()

  AK_PROJ_NAME="$(get_proj_name)"

  TESTABLES=""
  if [ -d test ]; then
    cd test

    if ! [ -f .not-actually-ci-tests ]; then
      TESTABLES="$TESTABLES ."
    fi

    if [ -z "$NO_DOCTESTS" ]; then
      RST_FILES=(../doc/*.rst)

      for f in "${RST_FILES[@]}"; do
        if [ -e "$f" ]; then
          if ! grep -q no-doctest "$f"; then
            TESTABLES="$TESTABLES $f"
          fi
        fi
      done

      # macOS bash is too old for mapfile: Oh well, no doctests on mac.
      if [ "$(uname)" != "Darwin" ]; then
        mapfile -t DOCTEST_MODULES < <( git grep -l doctest -- ":(glob,top)$AK_PROJ_NAME/**/*.py" )
        TESTABLES="$TESTABLES ${DOCTEST_MODULES[*]}"
      fi
    fi

    if [[ -n "$TESTABLES" ]]; then
      # Core dumps? Sure, take them.
      ulimit -c unlimited || true

      if test "$PLATFORM" != "Windows"; then
        # 10 GiB should be enough for just about anyone :)
        ulimit -m "$(python -c 'print(1024*1024*10)')" || true
      fi
  # {{{ configuration for test run

  if [[ $CISUPPORT_PARALLEL_PYTEST == "" || $CISUPPORT_PARALLEL_PYTEST == "xdist" ]]; then
    # Default: parallel if Not (Gitlab and GPU CI)?
@@ -409,6 +376,57 @@ test_py_project()
    CI_SUPPORT_LD_PRELOAD="$LD_PRELOAD"
  fi

  # Core dumps? Sure, take them.
  ulimit -c unlimited || true

  if test "$PLATFORM" != "Windows"; then
    # 10 GiB should be enough for just about anyone :)
    ulimit -m "$(python -c 'print(1024*1024*10)')" || true
  fi

  # }}}

  TESTABLES=""
  if [ -d test ]; then
    cd test

    if ! [ -f .not-actually-ci-tests ]; then
      TESTABLES="$TESTABLES ."
    fi

    if [ -z "$NO_DOCTESTS" ]; then
      RST_FILES=(../doc/*.rst)

      for f in "${RST_FILES[@]}"; do
        if [ -e "$f" ]; then
          if ! grep -q no-doctest "$f"; then
            TESTABLES="$TESTABLES $f"
          fi
        fi
      done

      # macOS bash is too old for mapfile: Oh well, no doctests on mac.
      if [ "$(uname)" != "Darwin" ]; then
        mapfile -t DOCTEST_MODULES < <( git grep -l doctest -- ":(glob,top)$AK_PROJ_NAME/**/*.py" )
        TESTABLES="$TESTABLES ${DOCTEST_MODULES[*]}"
      fi
    fi
  elif [ -d $AK_PROJ_NAME/test ]; then
    TESTABLES="$AK_PROJ_NAME $TESTABLES"

    if [ -z "$NO_DOCTESTS" ]; then
      RST_FILES=(doc/*.rst)

      for f in "${RST_FILES[@]}"; do
        if [ -e "$f" ]; then
          if ! grep -q no-doctest "$f"; then
            TESTABLES="$TESTABLES $f"
          fi
        fi
      done
    fi
  fi

  ( LD_PRELOAD="$CI_SUPPORT_LD_PRELOAD" with_echo "${PY_EXE}" -m pytest \
      --durations=10 \
      --tb=native  \
@@ -416,8 +434,6 @@ test_py_project()
      $DOCTEST_MODULES_FLAG \
      -rxsw \
      $PYTEST_FLAGS $PYTEST_PARALLEL_FLAGS $TESTABLES )
    fi
  fi
}

# }}}