diff --git a/Makefile b/Makefile index 669b2548..7c99a56e 100644 --- a/Makefile +++ b/Makefile @@ -34,13 +34,13 @@ debug: clean --define UVLOOP_DEBUG,CYTHON_TRACE,CYTHON_TRACE_NOGIL -docs: compile - cd docs && $(PYTHON) -m sphinx -a -b html . _build/html +docs: + $(PYTHON) setup.py build_ext --inplace build_sphinx test: - PYTHONASYNCIODEBUG=1 $(PYTHON) -m unittest discover -s tests - $(PYTHON) -m unittest discover -s tests + PYTHONASYNCIODEBUG=1 $(PYTHON) setup.py test + $(PYTHON) setup.py test release: distclean compile test diff --git a/setup.py b/setup.py index ae9a65ac..dd1a1ce5 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,6 @@ import shutil import subprocess import sys -import unittest if sys.platform in ('win32', 'cygwin', 'cli'): @@ -29,12 +28,6 @@ LIBUV_BUILD_DIR = os.path.join(os.path.dirname(__file__), 'build', 'libuv') -def discover_tests(): - test_loader = unittest.TestLoader() - test_suite = test_loader.discover('tests', pattern='test_*.py') - return test_suite - - def _libuv_build_env(): env = os.environ.copy() @@ -80,6 +73,12 @@ class uvloop_build_ext(build_ext): ] def initialize_options(self): + # initialize_options() may be called multiple times on the + # same command object, so make sure not to override previously + # set options. + if getattr(self, '_initialized', False): + return + super().initialize_options() self.use_system_libuv = False self.cython_always = False @@ -87,6 +86,12 @@ def initialize_options(self): self.cython_directives = None def finalize_options(self): + # finalize_options() may be called multiple times on the + # same command object, so make sure not to override previously + # set options. + if getattr(self, '_initialized', False): + return + need_cythonize = self.cython_always cfiles = {} @@ -141,6 +146,8 @@ def finalize_options(self): super().finalize_options() + self._initialized = True + def _patch_cfile(self, cfile): # Patch Cython 'async def' coroutines to have a 'tp_iter' # slot, which makes them compatible with 'yield from' without @@ -303,5 +310,5 @@ def build_extensions(self): ], provides=['uvloop'], include_package_data=True, - test_suite='setup.discover_tests' + test_suite='tests.suite' ) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..51eccca1 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,7 @@ +import unittest + + +def suite(): + test_loader = unittest.TestLoader() + test_suite = test_loader.discover('.', pattern='test_*.py') + return test_suite