pytest integration for ngrok.io
from PyPi
pip install pytest-ngrok
or from git
pip install -e git+https://github.com/Apkawa/pytest-ngrok.git#egg=pytest-ngrok
import pytest
from urllib.error import HTTPError
from urllib.request import urlopen
def test_ngrok(ngrok, httpserver):
httpserver.expect_request("/foobar").respond_with_data("ok")
remote_url = ngrok(httpserver.port)
assert urlopen(remote_url + "/foobar").read() == b'ok'
def test_ngrok_context_manager(ngrok, httpserver):
# example local server
httpserver.expect_request("/foobar").respond_with_data("ok")
with ngrok(httpserver.port) as remote_url:
_test_url = str(remote_url) + '/foobar'
assert urlopen(_test_url).read() == b'ok'
# Connection closes
pytest.raises(HTTPError, urlopen, _test_url)
With pytest-django
can use fixture live_server_ngrok
def test_server(live_server_ngrok):
assert live_server_ngrok.url.endswith('ngrok.io')
python -m venv /tmp/.venv/pytest-ngrok
source /tmp/.venv/pytest-ngrok/activate
pip install -r requirements-dev.txt
pytest
tox
python setup.py bumpversion
python setup.py publish