Skip to content

Commit 604a94f

Browse files
committed
Use py.test
1 parent 894a7c2 commit 604a94f

20 files changed

+127
-119
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ devdatabase.db
1717
bundle_version.gen
1818
celeryd.log
1919
celeryd.pid
20-
nosetests.xml
2120
coverage.xml
2221
cover/
2322
*.so
2423
.tox/
24+
.eggs/
25+
htmlcov/
26+
.cache/

MANIFEST.in

+6
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ recursive-include Doc *.rst *.py
88
recursive-include funtests *.py
99
recursive-include requirements *.txt
1010
recursive-include billiard *.py
11+
recursive-include t *.py
12+
13+
recursive-exclude docs/_build *
14+
recursive-exclude * __pycache__
15+
recursive-exclude * *.py[co]
16+
recursive-exclude * .*.sw*

billiard/tests/case.py

-6
This file was deleted.

billiard/tests/test_package.py

-12
This file was deleted.

billiard/tests/test_win32.py

-72
This file was deleted.

requirements/test-ci.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
coverage>=3.0
1+
pytest-cov

requirements/test.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
case>=1.2.2
1+
case>=1.3.1
2+
pytest>=3.0

setup.cfg

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
[nosetests]
2-
where = billiard/tests
1+
[tool:pytest]
2+
testpaths = t/unit/
3+
python_classes = test_*
4+

setup.py

+23-14
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import sys
55
import glob
66

7-
try:
8-
from setuptools import setup, Extension, find_packages
9-
except ImportError:
10-
from distutils.core import setup, Extension, find_packages # noqa
7+
import setuptools
8+
import setuptools.command.test
9+
1110
from distutils import sysconfig
1211
from distutils.errors import (
1312
CCompilerError,
@@ -99,15 +98,15 @@ def add_doc(m):
9998
HAVE_SEM_TIMEDWAIT=0,
10099
HAVE_FD_TRANSFER=1,
101100
HAVE_BROKEN_SEM_GETVALUE=1
102-
)
101+
)
103102
libraries = []
104103
elif sys.platform.startswith('cygwin'): # Cygwin
105104
macros = dict(
106105
HAVE_SEM_OPEN=1,
107106
HAVE_SEM_TIMEDWAIT=1,
108107
HAVE_FD_TRANSFER=0,
109108
HAVE_BROKEN_SEM_UNLINK=1
110-
)
109+
)
111110
libraries = []
112111
elif sys.platform in ('freebsd4', 'freebsd5', 'freebsd6'):
113112
# FreeBSD's P1003.1b semaphore support is very experimental
@@ -116,7 +115,7 @@ def add_doc(m):
116115
HAVE_SEM_OPEN=0,
117116
HAVE_SEM_TIMEDWAIT=0,
118117
HAVE_FD_TRANSFER=1,
119-
)
118+
)
120119
libraries = []
121120
elif re.match('^(gnukfreebsd(8|9|10|11)|freebsd(7|8|9|0))', sys.platform):
122121
macros = dict( # FreeBSD 7+ and GNU/kFreeBSD 8+
@@ -191,11 +190,23 @@ def _is_build_command(argv=sys.argv, cmds=('install', 'build', 'bdist')):
191190
return arg
192191

193192

193+
class pytest(setuptools.command.test.test):
194+
user_options = [('pytest-args=', 'a', 'Arguments to pass to py.test')]
195+
196+
def initialize_options(self):
197+
setuptools.command.test.test.initialize_options(self)
198+
self.pytest_args = []
199+
200+
def run_tests(self):
201+
import pytest
202+
sys.exit(pytest.main(self.pytest_args))
203+
204+
194205
def run_setup(with_extensions=True):
195206
extensions = []
196207
if with_extensions:
197208
extensions = [
198-
Extension(
209+
setuptools.Extension(
199210
'_billiard',
200211
sources=multiprocessing_srcs,
201212
define_macros=macros.items(),
@@ -206,7 +217,7 @@ def run_setup(with_extensions=True):
206217
]
207218
if sys.platform == 'win32':
208219
extensions.append(
209-
Extension(
220+
setuptools.Extension(
210221
'_winapi',
211222
sources=multiprocessing_srcs,
212223
define_macros=macros.items(),
@@ -215,10 +226,8 @@ def run_setup(with_extensions=True):
215226
depends=glob.glob('Modules/_billiard/*.h') + ['setup.py'],
216227
),
217228
)
218-
packages = find_packages(exclude=[
219-
'ez_setup', 'tests', 'funtests.*', 'tests.*',
220-
])
221-
setup(
229+
packages = setuptools.find_packages(exclude=['ez_setup', 't', 't.*'])
230+
setuptools.setup(
222231
name='billiard',
223232
version=meta['VERSION'],
224233
description=meta['doc'],
@@ -233,7 +242,7 @@ def run_setup(with_extensions=True):
233242
zip_safe=False,
234243
license='BSD',
235244
tests_require=reqs('test.txt'),
236-
test_suite='nose.collector',
245+
cmdclass={'test': pytest},
237246
classifiers=[
238247
'Development Status :: 5 - Production/Stable',
239248
'Intended Audience :: Developers',

t/__init__.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

billiard/tests/test_common.py renamed to t/unit/test_common.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
from __future__ import absolute_import
22

33
import os
4+
import pytest
45
import signal
56

67
from contextlib import contextmanager
78
from time import time
89

10+
from case import Mock, call, patch, skip
11+
912
from billiard.common import (
1013
_shutdown_cleanup,
1114
reset_signals,
1215
restart_state,
1316
)
1417

15-
from .case import Case, Mock, call, patch, skip
16-
1718

1819
def signo(name):
1920
return getattr(signal, name)
@@ -31,13 +32,13 @@ def termsigs(default, full):
3132

3233

3334
@skip.if_win32()
34-
class test_reset_signals(Case):
35+
class test_reset_signals:
3536

3637
def test_shutdown_handler(self):
3738
with patch('sys.exit') as exit:
3839
_shutdown_cleanup(15, Mock())
3940
exit.assert_called()
40-
self.assertEqual(os.WTERMSIG(exit.call_args[0][0]), 15)
41+
assert os.WTERMSIG(exit.call_args[0][0]) == 15
4142

4243
def test_does_not_reset_ignored_signal(self, sigs=['SIGTERM']):
4344
with self.assert_context(sigs, [], signal.SIG_IGN) as (_, SET):
@@ -79,20 +80,20 @@ def assert_context(self, default, full, get_returns=None, set_effect=None):
7980
yield GET, SET
8081

8182

82-
class test_restart_state(Case):
83+
class test_restart_state:
8384

8485
def test_raises(self):
8586
s = restart_state(100, 1) # max 100 restarts in 1 second.
8687
s.R = 99
8788
s.step()
88-
with self.assertRaises(s.RestartFreqExceeded):
89+
with pytest.raises(s.RestartFreqExceeded):
8990
s.step()
9091

9192
def test_time_passed_resets_counter(self):
9293
s = restart_state(100, 10)
9394
s.R, s.T = 100, time()
94-
with self.assertRaises(s.RestartFreqExceeded):
95+
with pytest.raises(s.RestartFreqExceeded):
9596
s.step()
9697
s.R, s.T = 100, time()
9798
s.step(time() + 20)
98-
self.assertEqual(s.R, 1)
99+
assert s.R == 1

t/unit/test_package.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import absolute_import
2+
3+
import billiard
4+
5+
6+
def test_has_version():
7+
assert billiard.__version__
8+
assert isinstance(billiard.__version__, str)

t/unit/test_win32.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from __future__ import absolute_import
2+
3+
import pytest
4+
5+
from case import skip
6+
7+
from billiard.compat import _winapi
8+
9+
10+
@skip.unless_win32()
11+
class test_win32_module:
12+
13+
@pytest.mark.parametrize('name', [
14+
'NULL',
15+
'ERROR_ALREADY_EXISTS',
16+
'ERROR_PIPE_BUSY',
17+
'ERROR_PIPE_CONNECTED',
18+
'ERROR_SEM_TIMEOUT',
19+
'ERROR_MORE_DATA',
20+
'ERROR_BROKEN_PIPE',
21+
'ERROR_IO_PENDING',
22+
'ERROR_NETNAME_DELETED',
23+
'GENERIC_READ',
24+
'GENERIC_WRITE',
25+
'DUPLICATE_SAME_ACCESS',
26+
'DUPLICATE_CLOSE_SOURCE',
27+
'INFINITE',
28+
'NMPWAIT_WAIT_FOREVER',
29+
'OPEN_EXISTING',
30+
'PIPE_ACCESS_DUPLEX',
31+
'PIPE_ACCESS_INBOUND',
32+
'PIPE_READMODE_MESSAGE',
33+
'PIPE_TYPE_MESSAGE',
34+
'PIPE_UNLIMITED_INSTANCES',
35+
'PIPE_WAIT',
36+
'PROCESS_ALL_ACCESS',
37+
'PROCESS_DUP_HANDLE',
38+
'WAIT_OBJECT_0',
39+
'WAIT_ABANDONED_0',
40+
'WAIT_TIMEOUT',
41+
'FILE_FLAG_FIRST_PIPE_INSTANCE',
42+
'FILE_FLAG_OVERLAPPED',
43+
])
44+
def test_constants(self, name):
45+
assert getattr(_winapi, name) is not None
46+
47+
@pytest.mark.parametrize('name', [
48+
'Overlapped',
49+
'CloseHandle',
50+
'GetLastError',
51+
'OpenProcess',
52+
'ExitProcess',
53+
'ConnectNamedPipe',
54+
'CreateFile',
55+
'WriteFile',
56+
'ReadFile',
57+
'CreateNamedPipe',
58+
'SetNamedPipeHandleState',
59+
'WaitNamedPipe',
60+
'PeekNamedPipe',
61+
'WaitForMultipleObjects',
62+
'WaitForSingleObject',
63+
'GetCurrentProcess',
64+
'GetExitCodeProcess',
65+
'TerminateProcess',
66+
'DuplicateHandle',
67+
'CreatePipe',
68+
])
69+
def test_functions(self, name):
70+
assert getattr(_winapi, name)

tox.ini

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ envlist = 2.7, 3.4, 3.5, pypy, pypy3
44
[testenv]
55
distribute = True
66
sitepackages = False
7-
commands = nosetests --with-xunit \
8-
--xunit-file={toxinidir}/nosetests.xml
7+
commands = py.test -xv --cov=celery --cov-report=html
98
deps=
109
-r{toxinidir}/requirements/test-ci.txt
1110
-r{toxinidir}/requirements/test.txt

0 commit comments

Comments
 (0)