def test_merge_works_without_bind(self): """ merge_threadlocal returns values as normal even when there has been no previous calls to bind_threadlocal. """ clear_threadlocal() assert {"b": 2} == merge_threadlocal(None, None, {"b": 2})
def test_bind_and_merge(self): """ Binding a variable causes it to be included in the result of merge_threadlocal. """ bind_threadlocal(a=1) assert {"a": 1, "b": 2} == merge_threadlocal(None, None, {"b": 2})
def test_clear(self): """ The thread-local context can be cleared, causing any previously bound variables to not be included in merge_threadlocal's result. """ bind_threadlocal(a=1) clear_threadlocal() assert {"b": 2} == merge_threadlocal(None, None, {"b": 2})
def test_multiple_binds(self): """ Multiple calls to bind_threadlocal accumulate values instead of replacing them. """ bind_threadlocal(a=1, b=2) bind_threadlocal(c=3) assert {"a": 1, "b": 2, "c": 3} == merge_threadlocal( None, None, {"b": 2} )