Skip to content

Commit aada357

Browse files
committed
Merge branch 'main' into jp_web_app
2 parents 89564cf + fe60208 commit aada357

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

docs/index.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# pytest-jupyter
2+
3+
A set of [pytest plugins](https://docs.pytest.org/en/stable/plugins.html) for Jupyter libraries and extensions.
4+
5+
## Basic Usage
6+
7+
Install `pytest-jupyter` from PyPI using pip:
8+
```
9+
pip install pytest-jupyter
10+
```
11+
12+
Once it's installed, all fixtures from `pytest-jupyter` will be discoverable by Pytest. Pass any fixture to your unit test function to begin using it, like so:
13+
14+
```python
15+
async def test_jupyter_server_api(jp_fetch):
16+
# Send request to a temporary Jupyter Server Web Application
17+
response = await jp_fetch("api/spec.yml")
18+
19+
# Confirm that the request is successful.
20+
assert response.code == 200
21+
```
22+
23+
24+
```{toctree}
25+
:maxdepth: 2
26+
:hidden:
27+
28+
Core <plugins/jupyter_core>
29+
Server <plugins/jupyter_server>
30+
31+
```
32+
33+
## Search
34+
35+
* {ref}`genindex`
36+
* {ref}`modindex`
37+
* {ref}`search`

docs/plugins/jupyter_core.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Jupyter Core plugin
2+
3+
The following fixtures are useful for setting up a test environment for Jupyter extensions and applications.
4+
5+
## Fixtures
6+
7+
```{eval-rst}
8+
.. automodule:: pytest_jupyter.jupyter_core
9+
:members:
10+
```

docs/plugins/jupyter_server.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Jupyter Server plugin
2+
3+
The jupyter_server module provides fixtures for automatically setting-up/tearing-down Jupyter Servers.
4+
5+
You can make requests to a *test server* using the `jp_fetch` and `jp_ws_fetch` fixtures.
6+
7+
## Fixtures
8+
9+
```{eval-rst}
10+
.. automodule:: pytest_jupyter.jupyter_server
11+
:members:
12+
```

pytest_jupyter/jupyter_server.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,19 @@ def jp_base_url():
223223

224224
@pytest.fixture
225225
def jp_fetch(jp_serverapp, http_server_client, jp_auth_header, jp_base_url):
226-
"""Performs an HTTP request against the test server."""
226+
"""Sends an (asynchronous) HTTP request to a test server.
227+
228+
The fixture is a factory; it can be called like
229+
a function inside a unit test. Here's a basic
230+
example of how use this fixture:
231+
232+
.. code-block:: python
233+
234+
async def my_test(jp_fetch):
235+
236+
response = await jp_fetch("api", "spec.yaml")
237+
...
238+
"""
227239
def client_fetch(*parts, headers={}, params={}, **kwargs):
228240
# Handle URL strings
229241
path_url = url_escape(url_path_join(jp_base_url, *parts), plus=False)
@@ -240,7 +252,31 @@ def client_fetch(*parts, headers={}, params={}, **kwargs):
240252

241253
@pytest.fixture
242254
def jp_ws_fetch(jp_serverapp, jp_auth_header, jp_http_port):
243-
"""Performs a websocket request against the test server."""
255+
"""Sends a websocket request to a test server.
256+
257+
The fixture is a factory; it can be called like
258+
a function inside a unit test. Here's a basic
259+
example of how use this fixture:
260+
261+
.. code-block:: python
262+
263+
async def my_test(jp_fetch, jp_ws_fetch):
264+
# Start a kernel
265+
r = await jp_fetch(
266+
'api', 'kernels',
267+
method='POST',
268+
body=json.dumps({
269+
'name': "python3"
270+
})
271+
)
272+
kid = json.loads(r.body.decode())['id']
273+
274+
# Open a websocket connection.
275+
ws = await jp_ws_fetch(
276+
'api', 'kernels', kid, 'channels'
277+
)
278+
...
279+
"""
244280
def client_fetch(*parts, headers={}, params={}, **kwargs):
245281
# Handle URL strings
246282
path = url_escape(url_path_join(*parts), plus=False)

0 commit comments

Comments
 (0)