Skip to content

Commit 0dd8fb6

Browse files
committed
Fix running of setup.py test with recent setuptools.
Referencing "setup" in the "test_suite" setup() argument leads to setup.py being executed twice, which leads to a broken command behaviour.
1 parent 2e346c1 commit 0dd8fb6

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

Makefile

+4-12
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,13 @@ debug:
2828

2929

3030
test:
31-
PYTHONASYNCIODEBUG=1 $(PYTHON) -m unittest discover -s tests
32-
$(PYTHON) -m unittest discover -s tests
33-
USE_UVLOOP=1 $(PYTHON) -m unittest discover -s tests
31+
PYTHONASYNCIODEBUG=1 $(PYTHON) setup.py test
32+
$(PYTHON) setup.py test
33+
USE_UVLOOP=1 $(PYTHON) setup.py test
3434

3535

3636
quicktest:
37-
$(PYTHON) -m unittest discover -s tests
38-
39-
40-
sdist: clean compile test
41-
$(PYTHON) setup.py sdist
42-
43-
44-
release: clean compile test
45-
$(PYTHON) setup.py sdist upload
37+
$(PYTHON) setup.py test
4638

4739

4840
htmldocs: compile

setup.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import platform
1111
import re
1212
import sys
13-
import unittest
1413

1514
import setuptools
1615
from setuptools.command import build_ext as _build_ext
@@ -29,12 +28,6 @@
2928
CFLAGS.extend(['-Wall', '-Wsign-compare', '-Wconversion'])
3029

3130

32-
def discover_tests():
33-
test_loader = unittest.TestLoader()
34-
test_suite = test_loader.discover('tests', pattern='test_*.py')
35-
return test_suite
36-
37-
3831
class build_ext(_build_ext.build_ext):
3932
user_options = _build_ext.build_ext.user_options + [
4033
('cython-always', None,
@@ -46,12 +39,24 @@ class build_ext(_build_ext.build_ext):
4639
]
4740

4841
def initialize_options(self):
42+
# initialize_options() may be called multiple times on the
43+
# same command object, so make sure not to override previously
44+
# set options.
45+
if getattr(self, '_initialized', False):
46+
return
47+
4948
super(build_ext, self).initialize_options()
5049
self.cython_always = False
5150
self.cython_annotate = None
5251
self.cython_directives = None
5352

5453
def finalize_options(self):
54+
# finalize_options() may be called multiple times on the
55+
# same command object, so make sure not to override previously
56+
# set options.
57+
if getattr(self, '_initialized', False):
58+
return
59+
5560
need_cythonize = self.cython_always
5661
cfiles = {}
5762

@@ -209,5 +214,5 @@ def _patch_cfile(self, cfile):
209214
extra_link_args=LDFLAGS)
210215
],
211216
cmdclass={'build_ext': build_ext},
212-
test_suite='setup.discover_tests',
217+
test_suite='tests.suite',
213218
)

tests/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import unittest
2+
3+
4+
def suite():
5+
test_loader = unittest.TestLoader()
6+
test_suite = test_loader.discover('.', pattern='test_*.py')
7+
return test_suite

0 commit comments

Comments
 (0)