4 ms·
It sounds like the testing frameworks in Python must be very limited if this is true.
by sinkasapa 12y ago
It sounds like the testing frameworks in Python must be very limited if this is true.
- raverbashing 12y agoIt's not about the testing framework, it's about not being able to access the inner function http://stackoverflow.com/questions/7054228/accessing-a-function-within-a-functionnested-function http://stackoverflow.com/questions/7054228/accessing-a-funct...
- kstrauser 12y agoThey're limited in the sense that they can't magically reach into a scope and inspect its private variables. (Not technically true - deep code inspection is possible. That wouldn't be the same as unit testing, though.)
- sinkasapa 12y agoWhy would you need to do this for a unit test? Can't you just test the properties of the return value of the outer function like you would for any other value? If the function returned an object, how would that be different?
- kstrauser 12y agoOK, I think some wires got crossed. You can trivially create a unit test for the outer function that indirectly tests the output of the inner function. What the GGP meant was that you can't directly test the inner function because you can't access it and so can't call inner() from the unit test. For example, given: def add(a, b): def inner(): return a + b return inner() You can write tests like: assert add(1, 2) == 3 But you can't write something like: assert add.inner() == 3 If inner() were doing something nontrivial, you'd probably want it to be standalone.