diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f71c6d20346a935749586919c2f135400805728b..73870cdf4fa95277cfa9f5e5afb7d6a9a92c6a93 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,17 +1,29 @@
 stages:
   - pretest
   - test
+  - nightly
+  - docs
   - deploy
 
 
+# --------------------------  Templates ------------------------------------------------------------------------------------
+
+# Base configuration for jobs meant to run at every commit
+.every-commit:
+  rules:
+    - if: $CI_PIPELINE_SOURCE != "schedule"
+
+# Base configuration for jobs meant to run at a schedule
+.scheduled:
+  rules:
+    - if: $CI_PIPELINE_SOURCE == "schedule"
+
 # --------------------------  Tests ------------------------------------------------------------------------------------
 
 # Normal test - runs on every commit all but "long run" tests
 tests-and-coverage:
   stage: pretest
-  except:
-    variables:
-      - $ENABLE_NIGHTLY_BUILDS
+  extends: .every-commit
   image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
   before_script:
     - pip install -e .
@@ -65,9 +77,7 @@ tests-and-coverage-with-longrun:
 # pipeline with latest python version
 latest-python:
   stage: test
-  except:
-    variables:
-      - $ENABLE_NIGHTLY_BUILDS
+  extends: .every-commit
   image: i10git.cs.fau.de:5005/pycodegen/pycodegen/latest_python
   before_script:
     - pip install -e .
@@ -92,9 +102,6 @@ latest-python:
 # Minimal tests in windows environment
 #minimal-windows:
 #  stage: test
-#  except:
-#    variables:
-#      - $ENABLE_NIGHTLY_BUILDS
 #  tags:
 #    - win
 #  script:
@@ -108,9 +115,7 @@ latest-python:
 
 ubuntu:
   stage: test
-  except:
-    variables:
-      - $ENABLE_NIGHTLY_BUILDS
+  extends: .every-commit
   image: i10git.cs.fau.de:5005/pycodegen/pycodegen/ubuntu
   before_script:
     - ln -s /usr/include/locale.h /usr/include/xlocale.h
@@ -134,9 +139,7 @@ ubuntu:
 
 .multiarch_template:
   stage: test
-  except:
-    variables:
-      - $ENABLE_NIGHTLY_BUILDS
+  extends: .every-commit
   before_script: &multiarch_before_script
     # - pip3 install -v .
     - export PYTHONPATH=src
@@ -205,9 +208,7 @@ riscv64:
 
 minimal-conda:
   stage: pretest
-  except:
-    variables:
-      - $ENABLE_NIGHTLY_BUILDS
+  extends: .every-commit
   image: i10git.cs.fau.de:5005/pycodegen/pycodegen/minimal_conda
   before_script:
     - pip install -e .
@@ -220,9 +221,7 @@ minimal-conda:
 
 minimal-sympy-master:
   stage: test
-  except:
-    variables:
-      - $ENABLE_NIGHTLY_BUILDS
+  extends: .every-commit
   image: i10git.cs.fau.de:5005/pycodegen/pycodegen/minimal_conda
   before_script:
     - pip install -e .
@@ -279,14 +278,42 @@ pycodegen-integration:
     reports:
       junit: pycodegen/*/report.xml
 
+
+# -------------------- Scheduled Tasks --------------------------------------------------------------------------
+
+
+# Nightly test against the latest (pre-release) version of SymPy published on PyPI
+nightly-sympy:
+  stage: nightly
+  needs: []
+  extends: .scheduled
+  image: i10git.cs.fau.de:5005/pycodegen/pycodegen/latest_python
+  before_script:
+    - pip install -e .
+    - pip install --upgrade --pre sympy
+  script:
+    - env
+    - pip list
+    - export NUM_CORES=$(nproc --all)
+    - mkdir -p ~/.config/matplotlib
+    - echo "backend:template" > ~/.config/matplotlib/matplotlibrc
+    - mkdir public
+    - pytest -v -n $NUM_CORES -m "not longrun" --junitxml=report.xml
+  tags:
+    - docker
+    - AVX
+    - cuda
+  artifacts:
+    when: always
+    reports:
+      junit: report.xml
+
 # -------------------- Linter & Documentation --------------------------------------------------------------------------
 
 
 flake8-lint:
   stage: pretest
-  except:
-    variables:
-      - $ENABLE_NIGHTLY_BUILDS
+  extends: .every-commit
   image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
   script:
     - flake8 src/pystencils
@@ -295,8 +322,10 @@ flake8-lint:
 
 
 build-documentation:
-  stage: test
+  stage: docs
+  extends: .every-commit
   image: i10git.cs.fau.de:5005/pycodegen/pycodegen/documentation
+  needs: []
   before_script:
     - pip install -e .
   script:
@@ -312,7 +341,9 @@ build-documentation:
 
 pages:
   image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
+  # extends: .every-commit
   stage: deploy
+  needs: ["build-documentation"]
   script:
     - ls -l
     - mv coverage_report html_doc
diff --git a/pyproject.toml b/pyproject.toml
index 4403645197b1776f1aa8f4a09eb6c4dee7656b0b..1f02427860991ee2f181078c7744f2fcf773a010 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -12,7 +12,7 @@ authors = [
 ]
 license = { file = "COPYING.txt" }
 requires-python = ">=3.10"
-dependencies = ["sympy>=1.6,<=1.11.1", "numpy>=1.8.0", "appdirs", "joblib", "pyyaml"]
+dependencies = ["sympy>=1.9,<=1.12.1", "numpy>=1.8.0", "appdirs", "joblib", "pyyaml"]
 classifiers = [
     "Development Status :: 4 - Beta",
     "Framework :: Jupyter",
diff --git a/src/pystencils/boundaries/boundaryhandling.py b/src/pystencils/boundaries/boundaryhandling.py
index 949e4065ac20021bbccfa603175ffb1604522de1..15a1976e2f5c820f4e8b234f250568fe362f306c 100644
--- a/src/pystencils/boundaries/boundaryhandling.py
+++ b/src/pystencils/boundaries/boundaryhandling.py
@@ -35,11 +35,11 @@ class FlagInterface:
         >>> dh = create_data_handling((4, 5))
         >>> fi = FlagInterface(dh, 'flag_field', np.uint8)
         >>> assert dh.has_data('flag_field')
-        >>> fi.reserve_next_flag()
+        >>> int(fi.reserve_next_flag())
         2
-        >>> fi.reserve_flag(4)
+        >>> int(fi.reserve_flag(4))
         4
-        >>> fi.reserve_next_flag()
+        >>> int(fi.reserve_next_flag())
         8
     """
 
diff --git a/src/pystencils/utils.py b/src/pystencils/utils.py
index f872ae48a54a2ae8c9437ec826be9b51c061f52e..aef9ea152a548c97b920720b8f2d0f444e0f4b11 100644
--- a/src/pystencils/utils.py
+++ b/src/pystencils/utils.py
@@ -82,8 +82,8 @@ def boolean_array_bounding_box(boolean_array):
 
     >>> a = np.zeros((4, 4), dtype=bool)
     >>> a[1:-1, 1:-1] = True
-    >>> boolean_array_bounding_box(a)
-    [(1, 3), (1, 3)]
+    >>> boolean_array_bounding_box(a) == [(1, 3), (1, 3)]
+    True
     """
     dim = boolean_array.ndim
     shape = boolean_array.shape