Skip to content

Commit de97d74

Browse files
committed
feat(test): Move to pytest
1 parent a636d7a commit de97d74

35 files changed

+1153
-1042
lines changed

.travis.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,35 @@ matrix:
2020
- python: '2.7'
2121
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py27
2222
- python: '2.7'
23-
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27
23+
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27
2424
- python: '2.7'
2525
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py27-gevent
2626
- python: '2.7'
27-
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27-gevent
27+
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27-gevent
2828
- python: '2.7'
2929
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py27-eventlet
3030
- python: '2.7'
31-
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27-eventlet
31+
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27-eventlet
3232
- python: '3.6'
3333
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py36
3434
- python: '3.6'
3535
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py36-sasl
3636
- python: '3.6'
37-
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py36
37+
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py36
3838
- python: '3.6'
39-
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py36-sasl
39+
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py36-sasl
4040
- python: '3.7'
4141
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py37
4242
- python: '3.7'
4343
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py37-sasl
4444
- python: '3.7'
45-
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py37 DEPLOY=true
45+
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py37 DEPLOY=true
4646
- python: '3.7'
47-
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py37-sasl
47+
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py37-sasl
4848
- python: pypy
4949
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=pypy
5050
- python: 'pypy'
51-
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=pypy
51+
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=pypy
5252
notifications:
5353
email: false
5454
install:

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ Or to run individual tests:
4141

4242
```
4343
export ZOOKEEPER_PATH=/<path to current folder>/bin/zookeeper/
44-
bin/nosetests -s -d kazoo.tests.test_client:TestClient.test_create
44+
bin/pytest -v kazoo/tests/test_client.py::TestClient::test_create
4545
```
4646

47-
The nose test runner allows you to filter by test module, class or
47+
The pytest test runner allows you to filter by test module, class or
4848
individual test method.
4949

5050
If you made changes to the documentation, you can build it locally:

constraints.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Consistent testing environment.
2+
flake8==3.7.9
3+
mock==3.0.5
4+
objgraph==3.4.1
5+
pytest==4.6.9
6+
pytest-cov==2.8.1
7+
8+
# Documentation building.
9+
Jinja2==2.7.3
10+
Pygments==1.6
11+
Sphinx==1.2.2
12+
docutils==0.12

docs/testing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Testing
77
Kazoo has several test harnesses used internally for its own tests that are
88
exposed as public API's for use in your own tests for common Zookeeper cluster
99
management and session testing. They can be mixed in with your own `unittest`
10-
or `nose` tests along with a `mock` object that allows you to force specific
10+
or `pytest` tests along with a `mock` object that allows you to force specific
1111
`KazooClient` commands to fail in various ways.
1212

1313
The test harness needs to be able to find the Zookeeper Java libraries. You

kazoo/tests/test_barrier.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
import threading
22

3-
from nose.tools import eq_
4-
53
from kazoo.testing import KazooTestCase
64

75

86
class KazooBarrierTests(KazooTestCase):
97
def test_barrier_not_exist(self):
108
b = self.client.Barrier("/some/path")
11-
eq_(b.wait(), True)
9+
assert b.wait()
1210

1311
def test_barrier_exists(self):
1412
b = self.client.Barrier("/some/path")
1513
b.create()
16-
eq_(b.wait(0), False)
14+
assert not b.wait(0)
1715
b.remove()
18-
eq_(b.wait(), True)
16+
assert b.wait()
1917

2018
def test_remove_nonexistent_barrier(self):
2119
b = self.client.Barrier("/some/path")
22-
eq_(b.remove(), False)
20+
assert not b.remove()
2321

2422

2523
class KazooDoubleBarrierTests(KazooTestCase):
26-
2724
def test_basic_barrier(self):
2825
b = self.client.DoubleBarrier("/some/path", 1)
29-
eq_(b.participating, False)
26+
assert not b.participating
3027
b.enter()
31-
eq_(b.participating, True)
28+
assert b.participating
3229
b.leave()
33-
eq_(b.participating, False)
30+
assert not b.participating
3431

3532
def test_two_barrier(self):
3633
av = threading.Event()
@@ -61,23 +58,23 @@ def make_barrier_two():
6158
t2 = threading.Thread(target=make_barrier_two)
6259
t2.start()
6360

64-
eq_(b1.participating, False)
65-
eq_(b2.participating, False)
61+
assert not b1.participating
62+
assert not b2.participating
6663

6764
bv.set()
6865
av.wait()
6966
ev.wait()
70-
eq_(b1.participating, True)
71-
eq_(b2.participating, True)
67+
assert b1.participating
68+
assert b2.participating
7269

7370
av.clear()
7471
ev.clear()
7572

7673
release_all.set()
7774
av.wait()
7875
ev.wait()
79-
eq_(b1.participating, False)
80-
eq_(b2.participating, False)
76+
assert not b1.participating
77+
assert not b2.participating
8178
t1.join()
8279
t2.join()
8380

@@ -111,19 +108,19 @@ def make_barrier_two():
111108
t2 = threading.Thread(target=make_barrier_two)
112109
t2.start()
113110

114-
eq_(b1.participating, False)
115-
eq_(b2.participating, False)
111+
assert not b1.participating
112+
assert not b2.participating
116113

117114
bv.set()
118-
eq_(b1.participating, False)
119-
eq_(b2.participating, False)
115+
assert not b1.participating
116+
assert not b2.participating
120117
b3.enter()
121118
ev.wait()
122119
av.wait()
123120

124-
eq_(b1.participating, True)
125-
eq_(b2.participating, True)
126-
eq_(b3.participating, True)
121+
assert b1.participating
122+
assert b2.participating
123+
assert b3.participating
127124

128125
av.clear()
129126
ev.clear()
@@ -132,26 +129,26 @@ def make_barrier_two():
132129
b3.leave()
133130
av.wait()
134131
ev.wait()
135-
eq_(b1.participating, False)
136-
eq_(b2.participating, False)
137-
eq_(b3.participating, False)
132+
assert not b1.participating
133+
assert not b2.participating
134+
assert not b3.participating
138135
t1.join()
139136
t2.join()
140137

141138
def test_barrier_existing_parent_node(self):
142139
b = self.client.DoubleBarrier('/some/path', 1)
143-
self.assertFalse(b.participating)
140+
assert b.participating is False
144141
self.client.create('/some', ephemeral=True)
145142
# the barrier cannot create children under an ephemeral node
146143
b.enter()
147-
self.assertFalse(b.participating)
144+
assert b.participating is False
148145

149146
def test_barrier_existing_node(self):
150147
b = self.client.DoubleBarrier('/some', 1)
151-
self.assertFalse(b.participating)
148+
assert b.participating is False
152149
self.client.ensure_path(b.path)
153150
self.client.create(b.create_path, ephemeral=True)
154151
# the barrier will re-use an existing node
155152
b.enter()
156-
self.assertTrue(b.participating)
153+
assert b.participating is True
157154
b.leave()

kazoo/tests/test_build.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import os
22

3-
from nose import SkipTest
3+
import pytest
44

55
from kazoo.testing import KazooTestCase
66

77

88
class TestBuildEnvironment(KazooTestCase):
9-
109
def setUp(self):
1110
KazooTestCase.setUp(self)
1211
if not os.environ.get('TRAVIS'):
13-
raise SkipTest('Only run build config tests on Travis.')
12+
pytest.skip('Only run build config tests on Travis.')
1413

1514
def test_zookeeper_version(self):
1615
server_version = self.client.server_version()
@@ -20,4 +19,4 @@ def test_zookeeper_version(self):
2019
if '-' in env_version:
2120
# Ignore pre-release markers like -alpha
2221
env_version = env_version.split('-')[0]
23-
self.assertEqual(env_version, server_version)
22+
assert env_version == server_version

0 commit comments

Comments
 (0)