__init__.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """Test suite for distutils.
  2. This test suite consists of a collection of test modules in the
  3. distutils.tests package. Each test module has a name starting with
  4. 'test' and contains a function test_suite(). The function is expected
  5. to return an initialized unittest.TestSuite instance.
  6. Tests for the command classes in the distutils.command package are
  7. included in distutils.tests as well, instead of using a separate
  8. distutils.command.tests package, since command identification is done
  9. by import rather than matching pre-defined names.
  10. """
  11. import os
  12. import sys
  13. import unittest
  14. import warnings
  15. from test.support import run_unittest
  16. here = os.path.dirname(__file__) or os.curdir
  17. def test_suite():
  18. old_filters = warnings.filters[:]
  19. suite = unittest.TestSuite()
  20. for fn in os.listdir(here):
  21. if fn.startswith("test") and fn.endswith(".py"):
  22. modname = "distutils.tests." + fn[:-3]
  23. __import__(modname)
  24. module = sys.modules[modname]
  25. suite.addTest(module.test_suite())
  26. # bpo-40055: Save/restore warnings filters to leave them unchanged.
  27. # Importing tests imports docutils which imports pkg_resources which adds a
  28. # warnings filter.
  29. warnings.filters[:] = old_filters
  30. return suite
  31. if __name__ == "__main__":
  32. run_unittest(test_suite())