https://github.com/apkawa/pytest-ngrok
pytest integration for ngrok
https://github.com/apkawa/pytest-ngrok
Last synced: 10 months ago
JSON representation
pytest integration for ngrok
- Host: GitHub
- URL: https://github.com/apkawa/pytest-ngrok
- Owner: Apkawa
- License: mit
- Created: 2020-01-16T14:46:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-01-10T16:25:20.000Z (over 1 year ago)
- Last Synced: 2025-09-01T04:38:31.976Z (11 months ago)
- Language: Python
- Size: 72.3 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pytest-ngrok.readthedocs.io/en/latest/?badge=latest)
[](https://github.com/Apkawa/pytest-django-ngrok/actions/workflows/ci.yml)
[](https://codecov.io/gh/Apkawa/pytest-ngrok)
[](https://pypi.python.org/pypi/pytest-ngrok)
[](https://pypi.python.org/pypi/pytest-ngrok)
[](LICENSE)
**Warning: This project will no longer be supported due to the ngrok service not working for me.**
pytest integration for [ngrok.io](https://ngrok.com/)
# Installation
from PyPi
```bash
pip install pytest-ngrok
```
or from git
```bash
pip install -e git+https://github.com/Apkawa/pytest-ngrok.git#egg=pytest-ngrok
```
# Usage
## Authtoken
Ways to pass token
1) `ngrok config add-authtoken $YOUR_AUTHTOKEN`
2) `~/.config/ngrok/ngrok.yml`
```yaml
version: 3
agent:
authtoken:
```
3) `export NGROK_AUTHTOKEN=$token$`
## Use in tests
```python
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`
```python
def test_server(live_server_ngrok):
assert live_server_ngrok.url.endswith('ngrok.io')
```