def test_decorator_runtime_code_replace(): remove_test_modules() from tests.patcher.first import decorated_func, another_decorated_func result = decorated_func(1) assert result == 2 result = another_decorated_func(3) assert result == 16 code = ''' def decorator(func): def inner(x): return func(x+3) return inner ''' patch('tests.patcher.first', code) result = decorated_func(1) assert result == 4 result = another_decorated_func(3) assert result == 36
def test_trivial_funcs_runtime_code_replace(): remove_test_modules() from tests.patcher.first import simple_func result = simple_func(1) assert result == 3 code = ''' def simple_func(x): return x + CONST + 1 ''' patch('tests.patcher.first', code) result = simple_func(1) assert result == 4
def test_decorated_funcs_runtime_code_replace(): remove_test_modules() from tests.patcher.first import decorated_func, another_decorated_func result = decorated_func(1) assert result == 2 result = another_decorated_func(3) assert result == 16 code = ''' @decorator def decorated_func(x): return x + 1 ''' patch('tests.patcher.first', code) result = decorated_func(1) assert result == 3 result = another_decorated_func(3) assert result == 16