Skip to content

Commit

Permalink
feat(test): Move to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
ceache committed Apr 15, 2020
1 parent a636d7a commit de97d74
Show file tree
Hide file tree
Showing 35 changed files with 1,153 additions and 1,042 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@ matrix:
- python: '2.7'
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py27
- python: '2.7'
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27
- python: '2.7'
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py27-gevent
- python: '2.7'
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27-gevent
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27-gevent
- python: '2.7'
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py27-eventlet
- python: '2.7'
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27-eventlet
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py27-eventlet
- python: '3.6'
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py36
- python: '3.6'
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py36-sasl
- python: '3.6'
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py36
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py36
- python: '3.6'
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py36-sasl
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py36-sasl
- python: '3.7'
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py37
- python: '3.7'
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=py37-sasl
- python: '3.7'
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py37 DEPLOY=true
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py37 DEPLOY=true
- python: '3.7'
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py37-sasl
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=py37-sasl
- python: pypy
env: ZOOKEEPER_VERSION=3.4.14 TOX_VENV=pypy
- python: 'pypy'
env: ZOOKEEPER_VERSION=3.5.6 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=pypy
env: ZOOKEEPER_VERSION=3.5.7 ZOOKEEPER_PREFIX="apache-" ZOOKEEPER_SUFFIX="-bin" ZOOKEEPER_LIB="lib" TOX_VENV=pypy
notifications:
email: false
install:
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ Or to run individual tests:

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

The nose test runner allows you to filter by test module, class or
The pytest test runner allows you to filter by test module, class or
individual test method.

If you made changes to the documentation, you can build it locally:
Expand Down
12 changes: 12 additions & 0 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Consistent testing environment.
flake8==3.7.9
mock==3.0.5
objgraph==3.4.1
pytest==4.6.9
pytest-cov==2.8.1

# Documentation building.
Jinja2==2.7.3
Pygments==1.6
Sphinx==1.2.2
docutils==0.12
2 changes: 1 addition & 1 deletion docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Testing
Kazoo has several test harnesses used internally for its own tests that are
exposed as public API's for use in your own tests for common Zookeeper cluster
management and session testing. They can be mixed in with your own `unittest`
or `nose` tests along with a `mock` object that allows you to force specific
or `pytest` tests along with a `mock` object that allows you to force specific
`KazooClient` commands to fail in various ways.

The test harness needs to be able to find the Zookeeper Java libraries. You
Expand Down
57 changes: 27 additions & 30 deletions kazoo/tests/test_barrier.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
import threading

from nose.tools import eq_

from kazoo.testing import KazooTestCase


class KazooBarrierTests(KazooTestCase):
def test_barrier_not_exist(self):
b = self.client.Barrier("/some/path")
eq_(b.wait(), True)
assert b.wait()

def test_barrier_exists(self):
b = self.client.Barrier("/some/path")
b.create()
eq_(b.wait(0), False)
assert not b.wait(0)
b.remove()
eq_(b.wait(), True)
assert b.wait()

def test_remove_nonexistent_barrier(self):
b = self.client.Barrier("/some/path")
eq_(b.remove(), False)
assert not b.remove()


class KazooDoubleBarrierTests(KazooTestCase):

def test_basic_barrier(self):
b = self.client.DoubleBarrier("/some/path", 1)
eq_(b.participating, False)
assert not b.participating
b.enter()
eq_(b.participating, True)
assert b.participating
b.leave()
eq_(b.participating, False)
assert not b.participating

def test_two_barrier(self):
av = threading.Event()
Expand Down Expand Up @@ -61,23 +58,23 @@ def make_barrier_two():
t2 = threading.Thread(target=make_barrier_two)
t2.start()

eq_(b1.participating, False)
eq_(b2.participating, False)
assert not b1.participating
assert not b2.participating

bv.set()
av.wait()
ev.wait()
eq_(b1.participating, True)
eq_(b2.participating, True)
assert b1.participating
assert b2.participating

av.clear()
ev.clear()

release_all.set()
av.wait()
ev.wait()
eq_(b1.participating, False)
eq_(b2.participating, False)
assert not b1.participating
assert not b2.participating
t1.join()
t2.join()

Expand Down Expand Up @@ -111,19 +108,19 @@ def make_barrier_two():
t2 = threading.Thread(target=make_barrier_two)
t2.start()

eq_(b1.participating, False)
eq_(b2.participating, False)
assert not b1.participating
assert not b2.participating

bv.set()
eq_(b1.participating, False)
eq_(b2.participating, False)
assert not b1.participating
assert not b2.participating
b3.enter()
ev.wait()
av.wait()

eq_(b1.participating, True)
eq_(b2.participating, True)
eq_(b3.participating, True)
assert b1.participating
assert b2.participating
assert b3.participating

av.clear()
ev.clear()
Expand All @@ -132,26 +129,26 @@ def make_barrier_two():
b3.leave()
av.wait()
ev.wait()
eq_(b1.participating, False)
eq_(b2.participating, False)
eq_(b3.participating, False)
assert not b1.participating
assert not b2.participating
assert not b3.participating
t1.join()
t2.join()

def test_barrier_existing_parent_node(self):
b = self.client.DoubleBarrier('/some/path', 1)
self.assertFalse(b.participating)
assert b.participating is False
self.client.create('/some', ephemeral=True)
# the barrier cannot create children under an ephemeral node
b.enter()
self.assertFalse(b.participating)
assert b.participating is False

def test_barrier_existing_node(self):
b = self.client.DoubleBarrier('/some', 1)
self.assertFalse(b.participating)
assert b.participating is False
self.client.ensure_path(b.path)
self.client.create(b.create_path, ephemeral=True)
# the barrier will re-use an existing node
b.enter()
self.assertTrue(b.participating)
assert b.participating is True
b.leave()
7 changes: 3 additions & 4 deletions kazoo/tests/test_build.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import os

from nose import SkipTest
import pytest

from kazoo.testing import KazooTestCase


class TestBuildEnvironment(KazooTestCase):

def setUp(self):
KazooTestCase.setUp(self)
if not os.environ.get('TRAVIS'):
raise SkipTest('Only run build config tests on Travis.')
pytest.skip('Only run build config tests on Travis.')

def test_zookeeper_version(self):
server_version = self.client.server_version()
Expand All @@ -20,4 +19,4 @@ def test_zookeeper_version(self):
if '-' in env_version:
# Ignore pre-release markers like -alpha
env_version = env_version.split('-')[0]
self.assertEqual(env_version, server_version)
assert env_version == server_version
Loading

0 comments on commit de97d74

Please sign in to comment.