added robustness in the environmental tests by resetting the environment...

... variable and the dynamic loading tests by making sure to delete and close opened library modules.

these comprise changes made to add some robustness when investigating #595