Skip to content
/ surgery Public

A decorator for unittest to get functions which are defined in a function.

License

Notifications You must be signed in to change notification settings

kozmof/surgery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

surgery

alt image alt image

A decorator for testing functions which are defined in a function. When you need to snap off surgery, pass False.

Usage

@surgery(True)
def main(x, y, z):
    def test1(a):
        print(10 + a + x)

    def test2():
        print(100)

    def test3():
        print(z)

    def test4(a, b, c, d):
        print(a, b, c, d)

    def test5():
        return 150
        
if __name__ == "__main__":
    inner_f = main(50, 100, 200)
    inner_f['test1'](100) # 160
    inner_f['test2']() # 100
    inner_f['test3']() # 200
    inner_f['test4'](1, 2, 3, 4) # 1 2 3 4
    print(inner_f['test5']()) # 150

Limitation

In an inner function, using a value defined in an outer function is not available.

Licence

MIT

About

A decorator for unittest to get functions which are defined in a function.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages