agiledragon / gomonkey

gomonkey is a library to make monkey patching in unit tests easy
MIT License
2k stars 179 forks source link

mock function affect other tests after Patches.Reset() #21

Open acgcc12 opened 4 years ago

acgcc12 commented 4 years ago

func TestA(t *testing.T) { Convey("TestA", t, func() { Convey(" test1", func() { Patches := ApplyFunc(upgrade, func( int , uint) int{ return 10 }) defer Patches.Reset() }) } func upgrade(age int, num uint) int { }

func TestB(t *testing.T){ Cover("TestB",t,func(){ res := upgrade(1,1) //it should be return 11 but affect by mock in TestA So(res, ShouldEqual, 11) })

agiledragon commented 4 years ago

Can your code run?