Clean up state after in process pytest runs #3016
Internal pytest test suite improvements:
nicoddemus left a comment
Thanks @jurko-gospodnetic, this looks like a nice cleanup!
I think this should go into
I don't have time to make a more in depth review right now (I should be in bed already), hopefully I will have more time tomorrow.
@nicoddemus - as for targeting the
But I'll move it to
Now extracted to new CwdSnapshot, SysModulesSnapshot & SysPathsSnapshot classes, each saving the state they are interested in on instantiation and restoring it in its `restore()` method.
Now each in-process pytest run saves a snapshot of important global Python state and restores it after the test completes, including the list of loaded modules & the Python path settings. Previously only the loaded package data was getting restored, but that was also reverting any loaded package changes done in the test triggering the pytest runs, and not only those done by the pytest runs themselves. Updated acceptance tests broken by this change, which were only passing before by accident as they were making multiple pytest runs with later ones depending on sys.path changes left behind by the initial one.