replacing warnings.formatwarnings and to reverse replacement of warnings.showwarnings when import is complete and when main function exits. Add test_warning.py. Vinay Sajip provided capture_warnings function.