Skip to content

Commit

Permalink
Remove test suite construction in distutils.tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jul 30, 2022
1 parent 36bb0a9 commit e945a1d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 52 deletions.
38 changes: 2 additions & 36 deletions distutils/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
"""Test suite for distutils.
This test suite consists of a collection of test modules in the
distutils.tests package. Each test module has a name starting with
'test' and contains a function test_suite(). The function is expected
to return an initialized unittest.TestSuite instance.
"""
Test suite for distutils.
Tests for the command classes in the distutils.command package are
included in distutils.tests as well, instead of using a separate
distutils.command.tests package, since command identification is done
by import rather than matching pre-defined names.
"""

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

from .py38compat 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())
16 changes: 0 additions & 16 deletions distutils/tests/py38compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,5 @@
)


# From Python 3.9
@contextlib.contextmanager
def _save_restore_warnings_filters():
old_filters = warnings.filters[:]
try:
yield
finally:
warnings.filters[:] = old_filters


try:
from test.support.warnings_helper import save_restore_warnings_filters
except (ModuleNotFoundError, ImportError):
save_restore_warnings_filters = _save_restore_warnings_filters


if sys.version_info < (3, 9):
requires_zlib = lambda: test.support.requires_zlib

0 comments on commit e945a1d

Please sign in to comment.