Hi, > 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 > hand, > 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 > documentation, > 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! Cheers
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4