Skip to content

Commit

Permalink
add tests for pytest plugin
Browse files Browse the repository at this point in the history
set minimum version of pytest in c-requirements
  • Loading branch information
samuelcolvin committed Jun 7, 2016
1 parent d8724a6 commit 1cbed6e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements-ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cython
chardet
tox
sphinxcontrib-newsfeed
pytest
pytest>=2.9.2
pytest-cov
gunicorn
pygments>=2.1
Expand Down
70 changes: 70 additions & 0 deletions tests/test_pytest_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
pytest_plugins = 'pytester'


def test_myplugin(testdir):
testdir.makepyfile("""\
import asyncio
import pytest
from aiohttp import web
pytest_plugins = 'aiohttp.pytest_plugins'
@asyncio.coroutine
def hello(request):
return web.Response(body=b'Hello, world')
def create_app(loop):
app = web.Application(loop=loop)
app.router.add_route('GET', '/', hello)
return app
@asyncio.coroutine
def test_hello(test_client):
client = yield from test_client(create_app)
resp = yield from client.get('/')
assert resp.status == 200
text = yield from resp.text()
assert 'Hello, world' in text
@asyncio.coroutine
def test_hello_with_loop(test_client, loop):
client = yield from test_client(create_app)
resp = yield from client.get('/')
assert resp.status == 200
text = yield from resp.text()
assert 'Hello, world' in text
@asyncio.coroutine
def test_hello_fails(test_client):
client = yield from test_client(create_app)
resp = yield from client.get('/')
assert resp.status == 200
text = yield from resp.text()
assert 'Hello, wield' in text
@asyncio.coroutine
def test_noop():
pass
@pytest.fixture
def client_alias(loop, test_client):
cli = loop.run_until_complete(test_client(create_app))
return cli
@asyncio.coroutine
def test_hello_with_alias(client_alias):
resp = yield from client_alias.get('/')
assert resp.status == 200
text = yield from resp.text()
assert 'Hello, world' in text
""")
result = testdir.runpytest()
result.assert_outcomes(passed=4, failed=1)

0 comments on commit 1cbed6e

Please sign in to comment.