I like to test my packages in python using the following code at the bottom of my package:
if __name__ == "__main__":
sys.exit(main())
where main() is a function I define above. Now my question is this:
I need to import extra packages in my main for testing my module that are NOT necessary to import if a user is just importing my module (ie. from another script). Is there a way to only import these extra packages if my main is explicitly run? And when my package is just imported (ie. from another script), these extra packages are NOT imported.
Why not put your import statements directly in the body of your
main()? That should do it.