diff --git a/cmake_integration.py b/cmake_integration.py
index 2ce021dff210ecf0f1e8248b55e75c3715ccd0ec..fba134ded1415aeb0fc36a449522cd8e0a2a1406 100644
--- a/cmake_integration.py
+++ b/cmake_integration.py
@@ -14,7 +14,8 @@ import sys
 import os
 import warnings
 
-__all__ = ['CodeGeneration']
+__all__ = ['CodeGeneration', 'ManualCodeGenerationContext']
+
 
 class CodeGeneration:
     def __init__(self):
@@ -76,3 +77,25 @@ class CodeGenerationContext:
         self.files_written.append(os.path.abspath(name))
         with open(name, 'w') as f:
             f.write(content)
+
+
+class ManualCodeGenerationContext:
+    """Context for testing - does not actually write files but puts them into a public dict
+    Environment parameters like if OpenMP, MPI or CPU-specific optimization should be used can be explicitly passed
+    to constructor instead of getting them from CMake
+    """
+    def __init__(self, openmp=False, optimize_for_localhost=False, mpi=True, double_accuracy=True):
+        self.openmp = openmp
+        self.optimize_for_localhost = optimize_for_localhost
+        self.mpi = mpi
+        self.double_accuracy = double_accuracy
+        self.files = dict()
+
+    def write_file(self, name, content):
+        self.files[name] = content
+
+    def __enter__(self):
+        return self
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        pass
diff --git a/codegen.py b/codegen.py
index 6bad99bd4d7dbe35ad92f4c61c3032b9de506a70..8f8e248dd75ff8274ae18b9d91b8f55463d439b5 100644
--- a/codegen.py
+++ b/codegen.py
@@ -20,7 +20,7 @@ def generate_sweep(generation_context, class_name, assignments,
     if hasattr(assignments, 'all_assignments'):
         assignments = assignments.all_assignments
 
-        create_kernel_params = default_create_kernel_parameters(generation_context, create_kernel_params)
+    create_kernel_params = default_create_kernel_parameters(generation_context, create_kernel_params)
 
     if not staggered:
         ast = create_kernel(assignments, **create_kernel_params)