Skip to content

Commit f7738b8

Browse files
authored
PYTHON-3887 Remove custom test command in setup.py (#1350)
1 parent 34da931 commit f7738b8

File tree

4 files changed

+2
-95
lines changed

4 files changed

+2
-95
lines changed

.evergreen/utils.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ createvirtualenv () {
3131

3232
python -m pip install --upgrade pip
3333
python -m pip install --upgrade setuptools wheel tox
34-
# lxml only has wheels for macos 10.15+
35-
python -m pip install unittest-xml-reporting || true
3634
}
3735

3836
# Usage:

mypy.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,3 @@ warn_unused_ignores = True
3737

3838
[mypy-winkerberos.*]
3939
ignore_missing_imports = True
40-
41-
[mypy-xmlrunner.*]
42-
ignore_missing_imports = True

setup.py

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,71 +8,11 @@
88
except ImportError:
99
pass
1010

11-
from setuptools import Command, setup
11+
from setuptools import setup
1212
from setuptools.command.build_ext import build_ext
1313
from setuptools.extension import Extension
1414

1515

16-
class test(Command):
17-
description = "run the tests"
18-
19-
user_options = [
20-
("test-module=", "m", "Discover tests in specified module"),
21-
("test-suite=", "s", "Test suite to run (e.g. 'some_module.test_suite')"),
22-
("failfast", "f", "Stop running tests on first failure or error"),
23-
("xunit-output=", "x", "Generate a results directory with XUnit XML format"),
24-
]
25-
26-
def initialize_options(self):
27-
self.test_module = None
28-
self.test_suite = None
29-
self.failfast = False
30-
self.xunit_output = None
31-
32-
def finalize_options(self):
33-
if self.test_suite is None and self.test_module is None:
34-
self.test_module = "test"
35-
elif self.test_module is not None and self.test_suite is not None:
36-
raise Exception("You may specify a module or suite, but not both")
37-
38-
def run(self):
39-
# Installing required packages, running egg_info and build_ext are
40-
# part of normal operation for setuptools.command.test.test
41-
if self.distribution.install_requires:
42-
self.distribution.fetch_build_eggs(self.distribution.install_requires)
43-
if self.distribution.tests_require:
44-
self.distribution.fetch_build_eggs(self.distribution.tests_require)
45-
if self.xunit_output:
46-
self.distribution.fetch_build_eggs(["unittest-xml-reporting"])
47-
self.run_command("egg_info")
48-
build_ext_cmd = self.reinitialize_command("build_ext")
49-
build_ext_cmd.inplace = 1
50-
self.run_command("build_ext")
51-
52-
# Construct a TextTestRunner directly from the unittest imported from
53-
# test, which creates a TestResult that supports the 'addSkip' method.
54-
# setuptools will by default create a TextTestRunner that uses the old
55-
# TestResult class.
56-
from test import PymongoTestRunner, test_cases, unittest
57-
58-
if self.test_suite is None:
59-
all_tests = unittest.defaultTestLoader.discover(self.test_module)
60-
suite = unittest.TestSuite()
61-
suite.addTests(sorted(test_cases(all_tests), key=lambda x: x.__module__))
62-
else:
63-
suite = unittest.defaultTestLoader.loadTestsFromName(self.test_suite)
64-
if self.xunit_output:
65-
from test import PymongoXMLTestRunner
66-
67-
runner = PymongoXMLTestRunner(
68-
verbosity=2, failfast=self.failfast, output=self.xunit_output
69-
)
70-
else:
71-
runner = PymongoTestRunner(verbosity=2, failfast=self.failfast)
72-
result = runner.run(suite)
73-
sys.exit(not result.wasSuccessful())
74-
75-
7616
class custom_build_ext(build_ext):
7717
"""Allow C extension building to fail.
7818
@@ -189,6 +129,4 @@ def build_extension(self, ext):
189129
)
190130
ext_modules = []
191131

192-
setup(
193-
cmdclass={"build_ext": custom_build_ext, "test": test}, ext_modules=ext_modules
194-
) # type:ignore
132+
setup(cmdclass={"build_ext": custom_build_ext}, ext_modules=ext_modules) # type:ignore

test/__init__.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@
2828
import unittest
2929
import warnings
3030

31-
try:
32-
from xmlrunner import XMLTestRunner
33-
34-
HAVE_XML = True
35-
# ValueError is raised when version 3+ is installed on Jython 2.7.
36-
except (ImportError, ValueError):
37-
HAVE_XML = False
38-
3931
try:
4032
import ipaddress # noqa
4133

@@ -1240,24 +1232,6 @@ def teardown():
12401232
print_running_clients()
12411233

12421234

1243-
class PymongoTestRunner(unittest.TextTestRunner):
1244-
def run(self, test):
1245-
setup()
1246-
result = super().run(test)
1247-
teardown()
1248-
return result
1249-
1250-
1251-
if HAVE_XML:
1252-
1253-
class PymongoXMLTestRunner(XMLTestRunner): # type: ignore[misc]
1254-
def run(self, test):
1255-
setup()
1256-
result = super().run(test)
1257-
teardown()
1258-
return result
1259-
1260-
12611235
def test_cases(suite):
12621236
"""Iterator over all TestCases within a TestSuite."""
12631237
for suite_or_case in suite._tests:

0 commit comments

Comments
 (0)