Commit 499226cc authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

In-package tests: run pytest in new subdir to avoid import ambiguity

parent 14759713
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -379,10 +379,15 @@ test_py_project()

  # }}}

  TESTABLES=""
  local CHANGE_TO_DIR

  if [ -d test ]; then
    # a no-op
    CHANGE_TO_DIR="."

    cd test

    TESTABLES=""
    if ! [ -f .not-actually-ci-tests ]; then
      TESTABLES="$TESTABLES ."
    fi
@@ -405,7 +410,12 @@ test_py_project()
      fi
    fi
  elif [ -d $AK_PROJ_NAME/test ]; then
    TESTABLES="$AK_PROJ_NAME $TESTABLES"
    # If we stay in the package root, then 'import packagename' is ambiguous,
    # and pytest gets angry with ImportPathMismatchError.
    mkdir test-run-dir
    CHANGE_TO_DIR="test-run-dir"

    TESTABLES="$AK_PROJ_NAME"

    if [ -z "$NO_DOCTESTS" ]; then
      RST_FILES=(doc/*.rst)
@@ -413,14 +423,15 @@ test_py_project()
      for f in "${RST_FILES[@]}"; do
        if [ -e "$f" ]; then
          if ! grep -q no-doctest "$f"; then
            TESTABLES="$TESTABLES $f"
            TESTABLES="$TESTABLES ../$f"
          fi
        fi
      done
    fi
  fi

  ( LD_PRELOAD="$CI_SUPPORT_LD_PRELOAD" with_echo "${PY_EXE}" -m pytest \
  ( cd "$CHANGE_TO_DIR" && \
    LD_PRELOAD="$CI_SUPPORT_LD_PRELOAD" with_echo "${PY_EXE}" -m pytest \
      --durations=10 \
      --tb=native  \
      --junitxml=pytest.xml \