diff --git a/unittests/test_apiutils.py b/unittests/test_apiutils.py
index 5fcc27dfa5ec31247f5788a7bb91570d29f7311f..22e9da17d0144cccb951b590042952a988c15545 100644
--- a/unittests/test_apiutils.py
+++ b/unittests/test_apiutils.py
@@ -70,17 +70,12 @@ def test_id_query():
     assert create_id_query(ids) == 'FIND ENTITY WITH ID=1 OR ID=2 OR ID=3 OR ID=4 OR ID=5'
 
 
-original_retrieve_entity_with_id = caosdb.apiutils.retrieve_entity_with_id
-
-
-def dummy_entity(eid):
-    return db.Record(id=eid)
-
-
-caosdb.apiutils.retrieve_entity_with_id = dummy_entity
-
-
 def test_resolve_reference():
+    original_retrieve_entity_with_id = caosdb.apiutils.retrieve_entity_with_id
+
+    def dummy_entity(eid):
+        return db.Record(id=eid)
+    caosdb.apiutils.retrieve_entity_with_id = dummy_entity
     prop = db.Property(id=1, datatype=db.REFERENCE, value=100)
     prop.is_valid = lambda: True
     items = [200, 300, 400]