[Python-Dev] Problems with regrtest and with logging
merwok at netwok.org
Mon May 9 18:42:06 CEST 2011
> When it comes to
> containers, identity matters at least as much as value does (and
> sometimes more so - e.g. sys.modules). Replacing those global
> containers with new ones isn't guaranteed to work, as they may be
> cached in various places rather than always retrieved fresh from the
> relevant module namespace. Modifying them in place, on the other
> does the right thing even in the presence of cached references.
That makes sense, thanks for the explanation!
> A comment to that effect may be a useful addition to regrtest, as I
> expect others may have similar questions about those identity checks
> in the future. (It may even be a useful addition to the
> but I have no idea where it could be sensibly included).
Somewhere in unittest doc, say in the section about tearDown. Or maybe
it’s time for a Python testing best practices howto?
> Also, don't be surprised if wholesale cleanup like that isn't
> completely reliable - it's far, far better if the test case
> understands the changes it is making (even indirectly) and explicitly
> reverses them.
Yep, I was probably bringing out the big guns too early.
self.addCleanup(sys.path.remove, path) is better and even shorter than
my previous code!
More information about the Python-Dev