????????????????????????????????????????????????buff?????????????????????????????????????????????????????????????á??????????????????????????ó??????????????????????????á?
??????????pytest?????????????????????????test_?????????????unittest???????pytest?в????setUp??????????????fixture????????????????????????????????????????????????????????????£??????setUp??tearDown?????????α???????
??????ó??????demo?????????????????????????????????????????г????Demo??????????????????顣
????import sys
????class Demo():
????def __init__(self):
????fail()
????def fail():
????if sys.argv[0].split('\')[-1].find('test') > -1:
????raise EnvironmentError(__name__)
????def success():
????print(__name__)
?????????????Demo?????????????fail???????????????pytest????????????raise???EnvironmentError????????????????Demo?????????????е?fail?????滻?success??????????????????????????
????import demo
????def test_demo():
????try:
????demo.Demo()
????except Exception as e:
????assert isinstance(e?? EnvironmentError)
????@replace#?滻???????????
????def test_replace_demo():
????demo.Demo()
???????У?replace???滻????????????????????????????
????def replace(fun):#???????????????????
????_ = demo.fail#????????е?fail??????????
????demo.fail = demo.success#????
????def inner():#???????
????fun()
????demo.fail = _#????????fail????
????return inner()
????????????????????????????????????д???????????????????????
??????????????????????closure????????????????????????к???????????????????????????????????????????????????????????????????“????”????“??????????????”???á?Э???????????‘Э’?????????У???“???????????????????????”???á?????????????????“?????????”??“???????????”??“?????????”???á?
?????????????????????????
????Closures are functions that refer to independent (free) variables (variables that are used locally?? but defined in an enclosing scope). In other words?? these functions 'remember' the environment in which they were created.
????????????????????????????????????????????python?к?????????????????????????????????????????????????????????????????????????????????????????????????inner??????????????????????????????inner????????????????????к?????У?????????????????????????

???????滹?и????????????????????inner??????a??b????inner???????a????test_closure???????????????????__closure__?????е???????__closure__???????a?????????b?????b?????inner?????????????????????a??????????????a??????????????????????????????pdb??????__closure__?????????b??
????def test_closure():
????a??b = 1??2
????def inner():
????print(a)
????return inner
????close = test_closure()
????print(close.__closure__[0])#<cell at 0x01CCC4B0: int object at 0x5B975910>
????????python?е?????javascript?е????????????????????????????js????????????python????????ο?js?????