From 8a6f7407b6eb635092c4aa4d35c975de801f780a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Wed, 1 Nov 2023 20:13:57 +0000 Subject: [PATCH 1/2] Drop support for TestCommand --- NEWS | 5 +- doc/for-test-authors.rst | 39 ------------ testtools/__init__.py | 2 - testtools/distutilscmd.py | 74 ---------------------- testtools/tests/__init__.py | 2 - testtools/tests/test_distutilscmd.py | 95 ---------------------------- 6 files changed, 4 insertions(+), 213 deletions(-) delete mode 100644 testtools/distutilscmd.py delete mode 100644 testtools/tests/test_distutilscmd.py diff --git a/NEWS b/NEWS index 2df18ed6..1914326f 100644 --- a/NEWS +++ b/NEWS @@ -3,7 +3,7 @@ testtools NEWS Changes and improvements to testtools_, grouped by release. -2.6.1 +2.7.0 ~~~~~ Improvements @@ -15,6 +15,9 @@ Improvements * Add typing in various modules (still lacking full coverage). (Jelmer Vernooij) +* Drop the 'test' command for distutils. This has been + deprecated since 2.6.0. (Jelmer Vernooij) + 2.6.0 ~~~~~ diff --git a/doc/for-test-authors.rst b/doc/for-test-authors.rst index 27ea2122..b081fb1c 100644 --- a/doc/for-test-authors.rst +++ b/doc/for-test-authors.rst @@ -88,43 +88,6 @@ of them will happily run testtools tests. In particular: From now on, we'll assume that you know how to run your tests. -Running test with Distutils -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. deprecated:: 2.6.0 - - Distutils integration was deprecated in 2.6.0. You should consider - replacing invocations of ``python setup.py test`` with a suitable - alternative such as ``tox``. Refer to `this issue`__ for more information. - - .. __: https://github.com/pypa/setuptools/issues/1684 - -If you are using Distutils_ to build your Python project, you can use the testtools -Distutils_ command to integrate testtools into your Distutils_ workflow:: - - from distutils.core import setup - from testtools import TestCommand - setup(name='foo', - version='1.0', - py_modules=['foo'], - cmdclass={'test': TestCommand} - ) - -You can then run:: - - $ python setup.py test -m exampletest - Tests running... - Ran 2 tests in 0.000s - - OK - -For more information about the capabilities of the `TestCommand` command see:: - - $ python setup.py test --help - -You can use the `setup configuration`_ to specify the default behavior of the -`TestCommand` command. - Assertions ========== @@ -1469,6 +1432,4 @@ Here, ``repr(nullary)`` will be the same as ``repr(f)``. .. _doctest: http://docs.python.org/library/doctest.html .. _Deferred: http://twistedmatrix.com/documents/current/core/howto/defer.html .. _discover: http://pypi.python.org/pypi/discover -.. _Distutils: http://docs.python.org/library/distutils.html -.. _`setup configuration`: http://docs.python.org/distutils/configfile.html .. _broken: http://chipaca.com/post/3210673069/hasattr-17-less-harmful diff --git a/testtools/__init__.py b/testtools/__init__.py index 6c8efbcc..c36308d5 100644 --- a/testtools/__init__.py +++ b/testtools/__init__.py @@ -21,7 +21,6 @@ 'ResourcedToStreamDecorator', 'Tagger', 'TestCase', - 'TestCommand', 'TestByTestResult', 'TestResult', 'TestResultDecorator', @@ -96,7 +95,6 @@ FixtureSuite, iterate_tests, ) -from testtools.distutilscmd import TestCommand # same format as sys.version_info: "A tuple containing the five components of # the version number: major, minor, micro, releaselevel, and serial. All diff --git a/testtools/distutilscmd.py b/testtools/distutilscmd.py deleted file mode 100644 index daf761fa..00000000 --- a/testtools/distutilscmd.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2010-2011 testtools developers . See LICENSE for details. - -"""Extensions to the standard Python unittest library.""" - -import sys -import warnings - -try: - from setuptools import Command - from setuptools.errors import OptionError -except ModuleNotFoundError: - from distutils.core import Command - from distutils.errors import DistutilsOptionError as OptionError - -from testtools.run import TestProgram, TestToolsTestRunner - - -class TestCommand(Command): - """Command to run unit tests with testtools""" - - description = "run unit tests with testtools" - - user_options = [ - ('catch', 'c', "Catch ctrl-C and display results so far"), - ('buffer', 'b', "Buffer stdout and stderr during tests"), - ('failfast', 'f', "Stop on first fail or error"), - ('test-module=', 'm', "Run 'test_suite' in specified module"), - ('test-suite=', 's', - "Test suite to run (e.g. 'some_module.test_suite')") - ] - - def __init__(self, dist): - Command.__init__(self, dist) - self.runner = TestToolsTestRunner(stdout=sys.stdout) - - warnings.warn( - "Distutils integration is deprecated and will be removed in the " - "next major release. " - "Refer to https://github.com/pypa/setuptools/issues/1684 for more " - "information.", - DeprecationWarning, - ) - - def initialize_options(self): - self.test_suite = None - self.test_module = None - self.catch = None - self.buffer = None - self.failfast = None - - def finalize_options(self): - if self.test_suite is None: - if self.test_module is None: - raise OptionError( - "You must specify a module or a suite to run tests from") - else: - self.test_suite = self.test_module+".test_suite" - elif self.test_module: - raise OptionError( - "You may specify a module or a suite, but not both") - self.test_args = [self.test_suite] - if self.verbose: - self.test_args.insert(0, '--verbose') - if self.buffer: - self.test_args.insert(0, '--buffer') - if self.catch: - self.test_args.insert(0, '--catch') - if self.failfast: - self.test_args.insert(0, '--failfast') - - def run(self): - self.program = TestProgram( - argv=self.test_args, testRunner=self.runner, stdout=sys.stdout, - exit=False) diff --git a/testtools/tests/__init__.py b/testtools/tests/__init__.py index 1a665641..2bd4d36e 100644 --- a/testtools/tests/__init__.py +++ b/testtools/tests/__init__.py @@ -15,7 +15,6 @@ def test_suite(): test_compat, test_content, test_content_type, - test_distutilscmd, test_fixturesupport, test_helpers, test_monkey, @@ -34,7 +33,6 @@ def test_suite(): test_compat, test_content, test_content_type, - test_distutilscmd, test_fixturesupport, test_helpers, test_monkey, diff --git a/testtools/tests/test_distutilscmd.py b/testtools/tests/test_distutilscmd.py deleted file mode 100644 index 29c35d02..00000000 --- a/testtools/tests/test_distutilscmd.py +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright (c) 2010-2011 Testtools authors. See LICENSE for details. - -"""Tests for the distutils test command logic.""" - -from distutils.dist import Distribution - -import testtools -from testtools.compat import _b -from testtools.distutilscmd import TestCommand -from testtools.helpers import try_import -from testtools.matchers import MatchesRegex -from testtools import TestCase - -fixtures = try_import('fixtures') - - -if fixtures: - class SampleTestFixture(fixtures.Fixture): - """Creates testtools.runexample temporarily.""" - - def __init__(self): - self.package = fixtures.PythonPackage( - 'runexample', [('__init__.py', _b(""" -from testtools import TestCase - -class TestFoo(TestCase): - def test_bar(self): - pass - def test_quux(self): - pass -def test_suite(): - from unittest import TestLoader - return TestLoader().loadTestsFromName(__name__) -"""))]) - - def setUp(self): - super().setUp() - self.useFixture(self.package) - testtools.__path__.append(self.package.base) - self.addCleanup(testtools.__path__.remove, self.package.base) - - -class TestCommandTest(TestCase): - - def setUp(self): - super().setUp() - if fixtures is None: - self.skipTest("Need fixtures") - - def test_test_module(self): - self.useFixture(SampleTestFixture()) - stdout = self.useFixture(fixtures.StringStream('stdout')) - dist = Distribution(attrs={ 'packages': ['testtools'] }) - dist.script_name = 'setup.py' - dist.script_args = ['test'] - dist.cmdclass = {'test': TestCommand} - dist.command_options = { - 'test': {'test_module': ('command line', 'testtools.runexample')}} - with fixtures.MonkeyPatch('sys.stdout', stdout.stream): - cmd = dist.reinitialize_command('test') - dist.run_command('test') - self.assertThat( - stdout.getDetails()['stdout'].as_text(), - MatchesRegex("""Tests running... - -Ran 2 tests in \\d.\\d\\d\\ds -OK -""")) - - def test_test_suite(self): - self.useFixture(SampleTestFixture()) - stdout = self.useFixture(fixtures.StringStream('stdout')) - dist = Distribution(attrs={ 'packages': ['testtools'] }) - dist.script_name = 'setup.py' - dist.script_args = ['test'] - dist.cmdclass = {'test': TestCommand} - dist.command_options = { - 'test': { - 'test_suite': ( - 'command line', 'testtools.runexample.test_suite')}} - with fixtures.MonkeyPatch('sys.stdout', stdout.stream): - cmd = dist.reinitialize_command('test') - dist.run_command('test') - self.assertThat( - stdout.getDetails()['stdout'].as_text(), - MatchesRegex("""Tests running... - -Ran 2 tests in \\d.\\d\\d\\ds -OK -""")) - - -def test_suite(): - from unittest import TestLoader - return TestLoader().loadTestsFromName(__name__) From e75ee0f5cea300cc20c8be764fb4bcf56d96ee97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Wed, 1 Nov 2023 20:15:10 +0000 Subject: [PATCH 2/2] Also remove TestCommand from setup.py --- setup.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/setup.py b/setup.py index e76930c5..57c98051 100755 --- a/setup.py +++ b/setup.py @@ -1,17 +1,7 @@ #!/usr/bin/env python import setuptools -try: - import testtools - cmd_class = {} - if getattr(testtools, 'TestCommand', None) is not None: - cmd_class['test'] = testtools.TestCommand -except: - cmd_class = None - - setuptools.setup( python_requires='>=3.6', - cmdclass=cmd_class, setup_requires=['pbr'], pbr=True)