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