from contextlib import contextmanager


@contextmanager
def assert_no_difference(func):
    """Asserts that the function result is unchanged after executing the block"""
    val = func()
    yield
    val_after = func()
    assert val_after == val, f'Result is not the same! Value before {val}, after: {val_after}'


@contextmanager
def assert_difference(func, diff):
    """
    Asserts that the function result has changed by `diff` after executing the block
    `diff` can be anything, but addition with the result of `func` must be defined.
    """
    val = func()
    yield
    val_after = func()
    assert val_after == val + diff, f'Result did not change by {diff}! Value before {val}, after: {val_after}'

@@ -78,16 +78,27 @@
 nce(func
+, name=None
 ):%0A    %22
@@ -228,40 +228,51 @@
 c()%0A
+%0A
     
+def 
 assert
- val_after == val, f'R
+ion_msg():%0A        msg = f'r
 esul
@@ -290,17 +290,17 @@
 e same! 
-V
+v
 alue bef
@@ -330,16 +330,135 @@
 after%7D'%0A
+        if name:%0A            return f'%7Bname%7D: ' + msg%0A        return msg%0A%0A    assert val_after == val, assertion_msg()%0A
 %0A%0A@conte
@@ -499,16 +499,27 @@
 nc, diff
+, name=None
 ):%0A    %22
@@ -752,53 +752,61 @@
 c()%0A
+%0A
     
+def 
 assert
- val_after == val + diff, f'R
+ion_msg():%0A        msg = f'r
 esult 
+for 
 did 
@@ -831,9 +831,9 @@
 f%7D! 
-V
+v
 alue
@@ -847,28 +847,154 @@
  %7Bval%7D, after: %7Bval_after%7D'%0A
+        if name:%0A            return f'%7Bname%7D: ' + msg%0A        return msg%0A%0A    assert val_after == val + diff, assertion_msg()%0A

add name arg assert_(no_)difference for better failure output