Use Python Decorators to Make Hoare Logic

I am relatively new to Python thanks to a solid experience in Java. I'm trying to create a basic class to make Hoare logic. Class decorators seem to be the solution. I have produced the following code, can you talk about it and suggest a simpler way to proceed? It seems terribly complicated to see how easy it would be with Java.

def hoare_logic (description, pre_execution = None, post_execution = None):
def decorator_func (function_to_decorate):
def wrapper_func (* arguments, ** kwargs):
# Prerequisite Hoare
if pre_execution is not None:
pre_condition = pre_execution (* arguments, ** kwargs)
print ("Hoare Pre-Condition {! r}". format (description, prerequisite))
# Hoare Command
return_value = function_to_decorate (* arguments, ** kwargs)

# Hoare Post-Condition
if post_execution is not None:
post_condition = post_execution (* arguments, ** kwargs)
print ("Hoare Post-Condition {! r}". format (description, post_condition))

return return_value

returns wrapper_func

return decorator_func

@hoare_logic (description = description of the unit test & # 39;)
def (arg) command:
if arg is not None:
print ("order")
if arg == & # 39; foobar & # 39 ;:
returns False
returns True
raises ValueError

#self.assertRaise (ValueError, Command, None)
command (True)
command (False)
command (& # 39; foo & # 39;)
Command bar & # 39;)
command (& # 39; foobar & # 39;)

Once I master the basic mechanism, I intend to adapt it to provide API contracts and a BDD scenario feature framework for unit testing. So please keep this in mind. I've deliberately excluded class wrapper and imports to simplify the task. I am interested in a thorough review of the implementation of basic features in Python. I am not sure of my treatment * args, ** kwargs but from what I can see, I need it for Python decorators. Is there a better way to manage the setting of the encapsulated function?

You will need to add them if you want to run it as a class, but it should run as a script. The commented line only works if it's a class, but not a script.

Please be nice, if I've broken the rules of the question, help me improve the compliance of the issue with the comments rather than just closing it.