__init__.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. from test.support import run_unittest, save_restore_warnings_filters
  15. here = os.path.dirname(__file__) or os.curdir
  16. def test_suite():
  17. suite = unittest.TestSuite()
  18. for fn in os.listdir(here):
  19. if fn.startswith("test") and fn.endswith(".py"):
  20. modname = "distutils.tests." + fn[:-3]
  21. # bpo-40055: Save/restore warnings filters to leave them unchanged.
  22. # Importing tests imports docutils which imports pkg_resources
  23. # which adds a warnings filter.
  24. with save_restore_warnings_filters():
  25. __import__(modname)
  26. module = sys.modules[modname]
  27. suite.addTest(module.test_suite())
  28. return suite
  29. if __name__ == "__main__":
  30. run_unittest(test_suite())