
import os
import sys
import unittest
import warnings
from test.support import run_unittest


here = os.path.dirname(__file__) or os.curdir


def test_suite():
    old_filters = warnings.filters[:]
    suite = unittest.TestSuite()
    for fn in os.listdir(here):
        if fn.startswith("test") and fn.endswith(".py"):
            modname = "distutils.tests." + fn[:-3]
            __import__(modname)
            module = sys.modules[modname]
            suite.addTest(module.test_suite())
    # bpo-40055: Save/restore warnings filters to leave them unchanged.
    # Importing tests imports docutils which imports pkg_resources which adds a
    # warnings filter.
    warnings.filters[:] = old_filters
    return suite


if __name__ == "__main__":
    run_unittest(test_suite())


import os
import sys
import unittest
from test.support import run_unittest
from test.support.warnings_helper import save_restore_warnings_filters


here = os.path.dirname(__file__) or os.curdir


def test_suite():
    suite = unittest.TestSuite()
    for fn in os.listdir(here):
        if fn.startswith("test") and fn.endswith(".py"):
            modname = "distutils.tests." + fn[:-3]
            # bpo-40055: Save/restore warnings filters to leave them unchanged.
            # Importing tests imports docutils which imports pkg_resources
            # which adds a warnings filter.
            with save_restore_warnings_filters():
                __import__(modname)
            module = sys.modules[modname]
            suite.addTest(module.test_suite())
    return suite


if __name__ == "__main__":
    run_unittest(test_suite())

Fix test_copyreg when numpy is installed (GH-20935)
bpo-41003: Fix test_copyreg when numpy is installed (GH-20935)

Fix test_copyreg when numpy is installed: test.pickletester now
saves/restores warnings.filters when importing numpy, to ignore
filters installed by numpy.

Add the save_restore_warnings_filters() function to the
test.support.warnings_helper module.
  
  import os
  import sys
  import unittest
- import warnings
  from test.support import run_unittest
+ from test.support.warnings_helper import save_restore_warnings_filters
  
  
  here = os.path.dirname(__file__) or os.curdir
  
  
  def test_suite():
-     old_filters = warnings.filters[:]
      suite = unittest.TestSuite()
      for fn in os.listdir(here):
          if fn.startswith("test") and fn.endswith(".py"):
              modname = "distutils.tests." + fn[:-3]
+             # bpo-40055: Save/restore warnings filters to leave them unchanged.
+             # Importing tests imports docutils which imports pkg_resources
+             # which adds a warnings filter.
+             with save_restore_warnings_filters():
-             __import__(modname)
+                 __import__(modname)
              module = sys.modules[modname]
              suite.addTest(module.test_suite())
-     # bpo-40055: Save/restore warnings filters to leave them unchanged.
-     # Importing tests imports docutils which imports pkg_resources which adds a
-     # warnings filter.
-     warnings.filters[:] = old_filters
      return suite
  
  
  if __name__ == "__main__":
      run_unittest(test_suite())
  
Fix test_copyreg when numpy is installed (GH-20935)
## Code Before:

import os
import sys
import unittest
import warnings
from test.support import run_unittest


here = os.path.dirname(__file__) or os.curdir


def test_suite():
    old_filters = warnings.filters[:]
    suite = unittest.TestSuite()
    for fn in os.listdir(here):
        if fn.startswith("test") and fn.endswith(".py"):
            modname = "distutils.tests." + fn[:-3]
            __import__(modname)
            module = sys.modules[modname]
            suite.addTest(module.test_suite())
    # bpo-40055: Save/restore warnings filters to leave them unchanged.
    # Importing tests imports docutils which imports pkg_resources which adds a
    # warnings filter.
    warnings.filters[:] = old_filters
    return suite


if __name__ == "__main__":
    run_unittest(test_suite())

## Instruction:
Fix test_copyreg when numpy is installed (GH-20935)
## Code After:

import os
import sys
import unittest
from test.support import run_unittest
from test.support.warnings_helper import save_restore_warnings_filters


here = os.path.dirname(__file__) or os.curdir


def test_suite():
    suite = unittest.TestSuite()
    for fn in os.listdir(here):
        if fn.startswith("test") and fn.endswith(".py"):
            modname = "distutils.tests." + fn[:-3]
            # bpo-40055: Save/restore warnings filters to leave them unchanged.
            # Importing tests imports docutils which imports pkg_resources
            # which adds a warnings filter.
            with save_restore_warnings_filters():
                __import__(modname)
            module = sys.modules[modname]
            suite.addTest(module.test_suite())
    return suite


if __name__ == "__main__":
    run_unittest(test_suite())
