Skip to content

Commit

Permalink
Fix running of setup.py test with recent setuptools. (#84)
Browse files Browse the repository at this point in the history
Referencing "setup" in the "test_suite" setup() argument leads to
setup.py being executed twice, which leads to a broken command
behaviour.
  • Loading branch information
elprans authored and 1st1 committed Mar 30, 2017
1 parent c841ab9 commit be920ea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import shutil
import subprocess
import sys
import unittest


if sys.platform in ('win32', 'cygwin', 'cli'):
Expand All @@ -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()

Expand Down Expand Up @@ -80,13 +73,25 @@ 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
self.cython_annotate = None
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 = {}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -303,5 +310,5 @@ def build_extensions(self):
],
provides=['uvloop'],
include_package_data=True,
test_suite='setup.discover_tests'
test_suite='tests.suite'
)
7 changes: 7 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import unittest


def suite():
test_loader = unittest.TestLoader()
test_suite = test_loader.discover('.', pattern='test_*.py')
return test_suite

0 comments on commit be920ea

Please sign in to comment.