diff --git a/.gitlab-ci/default.yml b/.gitlab-ci/default.yml
index 7248d1eab9341067a8a80a9fe2eda4b8437968c7..da57ba3d1e15602b87bacbc623a2243abe06e312 100644
--- a/.gitlab-ci/default.yml
+++ b/.gitlab-ci/default.yml
@@ -206,14 +206,8 @@ test python:
     OMPI_ALLOW_RUN_AS_ROOT_CONFIRM: 1
     DUMUX_NUM_THREADS: 4
   script:
-    # restore Python virtual env from cache (job:configure artifacts) (Dune 2.9)
     - |
-      if [ -d "build-cmake/dune-env" ]; then
-        rm -r /dune/modules/dune-common/build-cmake/dune-env
-        mv build-cmake/dune-env /dune/modules/dune-common/build-cmake/dune-env
-      fi
-    - |
-      if ([ ! -s changedfiles.txt ] || grep -q python "changedfiles.txt"); then
+      if ( [ -d "build-cmake/python" ] && ([ ! -s changedfiles.txt ] || grep -q python "changedfiles.txt")); then
         if [ ! -s changedfiles.txt ]; then
           echo "Skipping test selection: considering all Python tests."
         else
@@ -234,6 +228,11 @@ test python:
           cp /dune/modules/dune-istl/cmake/modules/FindSuperLU.cmake /dune/modules/opm-common/cmake/Modules/FindSuperLU.cmake
         fi
 
+        # restore Python virtual env from cache (job:configure artifacts) (Dune 2.9)
+        if [ -d "build-cmake/dune-env" ]; then
+          rm -r /dune/modules/dune-common/build-cmake/dune-env
+          mv build-cmake/dune-env /dune/modules/dune-common/build-cmake/dune-env
+        fi
         source bin/testing/ci-setup-python-env.sh
         pushd build-cmake
           DUNE_LOG_LEVEL=DEBUG ctest --output-on-failure -L python