Skip to content

Commit be920ea

Browse files
elprans1st1
authored andcommitted
Fix running of setup.py test with recent setuptools. (#84)
Referencing "setup" in the "test_suite" setup() argument leads to setup.py being executed twice, which leads to a broken command behaviour.
1 parent c841ab9 commit be920ea

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ debug: clean
3434
--define UVLOOP_DEBUG,CYTHON_TRACE,CYTHON_TRACE_NOGIL
3535

3636

37-
docs: compile
38-
cd docs && $(PYTHON) -m sphinx -a -b html . _build/html
37+
docs:
38+
$(PYTHON) setup.py build_ext --inplace build_sphinx
3939

4040

4141
test:
42-
PYTHONASYNCIODEBUG=1 $(PYTHON) -m unittest discover -s tests
43-
$(PYTHON) -m unittest discover -s tests
42+
PYTHONASYNCIODEBUG=1 $(PYTHON) setup.py test
43+
$(PYTHON) setup.py test
4444

4545

4646
release: distclean compile test

setup.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import shutil
55
import subprocess
66
import sys
7-
import unittest
87

98

109
if sys.platform in ('win32', 'cygwin', 'cli'):
@@ -29,12 +28,6 @@
2928
LIBUV_BUILD_DIR = os.path.join(os.path.dirname(__file__), 'build', 'libuv')
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
def _libuv_build_env():
3932
env = os.environ.copy()
4033

@@ -80,13 +73,25 @@ class uvloop_build_ext(build_ext):
8073
]
8174

8275
def initialize_options(self):
76+
# initialize_options() may be called multiple times on the
77+
# same command object, so make sure not to override previously
78+
# set options.
79+
if getattr(self, '_initialized', False):
80+
return
81+
8382
super().initialize_options()
8483
self.use_system_libuv = False
8584
self.cython_always = False
8685
self.cython_annotate = None
8786
self.cython_directives = None
8887

8988
def finalize_options(self):
89+
# finalize_options() may be called multiple times on the
90+
# same command object, so make sure not to override previously
91+
# set options.
92+
if getattr(self, '_initialized', False):
93+
return
94+
9095
need_cythonize = self.cython_always
9196
cfiles = {}
9297

@@ -141,6 +146,8 @@ def finalize_options(self):
141146

142147
super().finalize_options()
143148

149+
self._initialized = True
150+
144151
def _patch_cfile(self, cfile):
145152
# Patch Cython 'async def' coroutines to have a 'tp_iter'
146153
# slot, which makes them compatible with 'yield from' without
@@ -303,5 +310,5 @@ def build_extensions(self):
303310
],
304311
provides=['uvloop'],
305312
include_package_data=True,
306-
test_suite='setup.discover_tests'
313+
test_suite='tests.suite'
307314
)

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)