3 ms·
Right. One case in which I've come across this problem in Python is writing unit tests for code using Twisted (and Trial, Twisted's unit test framework) with @i
by lambda 12y ago
Right. One case in which I've come across this problem in Python is writing unit tests for code using Twisted (and Trial, Twisted's unit test framework) with @inlineCallbacks, and trying to also use this style of resource management for mocks (or, essentially the same, the @patch decorator to set up the mocks).
If you have something like:
@patch('some_module.some_object')
@inlineCallbacks
def test_my_stuff(self):
do_stuff()
yield some_operation()
do_more_stuff()
self.assertFalse(True)
Then you run into the problem that @patch has cleaned up all of your mocks by the time the yield returns.
Now, I haven't tried to do anything equivalent in Rust; I'm not sure what the idiomatic equivalent would be. But having more explicit control of lifetime, rather than it always depending specifically on that stack frame, seems like it might help here.