test: isolate _config in all tests#1549
Conversation
Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
leondz
left a comment
There was a problem hiding this comment.
there may be relevant deficiencies in the scope of importlib.reload(), otherwise lgtm, nice prune
| def reload(): | ||
| import importlib | ||
|
|
||
| importlib.reload(_config) |
There was a problem hiding this comment.
Is this sufficient? Do we not want to unload first with del _config?
There was a problem hiding this comment.
Per python docs:
The argument must be a module object, so it must have been successfully imported before.
I agree there may be an edge case not yet handled based on the details offered in the linked docs, but I suspect this provides a good baseline to build on.
There was a problem hiding this comment.
it does. Saw this in the docs and didn't see a reason not to gc the older version:
- As with all other objects in Python the old objects are only reclaimed after their reference counts drop to zero.
- The names in the module namespace are updated to point to any new or changed objects.
- Other references to the old objects (such as names external to the module) are not rebound to refer to the new objects and must be updated in each namespace where they occur if that is desired.
https://docs.python.org/3/library/importlib.html#importlib.reload
There was a problem hiding this comment.
A call to del may remove the object as no longer considered successfully imported, as garbage collection is not always predictable in terms of timing. Can do some testing, however I am not currently comfortable marking a required to exist item with del prior to replacement by importlib. We might be able to add an additional reference and offer that to del after a the reload however I suspect that may actually introduce more possible race conditions.
There was a problem hiding this comment.
I respect the reservation. I wonder if python supports making these two operations into an atomic txn. Or if .reload() is even possible after del()?
Signed-off-by: Jeffrey Martin <jemartin@nvidia.com>
The
_confignamespace is utilized globally. This revision ensures a clean configuration environment exists before each test and ensures post test cleanup of files connected to config that may have been created during the test.Verification
List the steps needed to make sure this thing works