Skip to content

Commit 5b3ada2

Browse files
committed
Remove entry points
1 parent a62846c commit 5b3ada2

File tree

7 files changed

+139
-37
lines changed

7 files changed

+139
-37
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
# pytest-jupyter
22

33
A set of pytest plugins for Jupyter libraries and extensions.
4+
5+
## Basic Usage
6+
7+
First, install `pytest-jupyter` from PyPI using pip:
8+
```bash
9+
pip install pytest-jupyter
10+
```
11+
This installs the basic pytest-jupyter package that insludes fixture definitions for the various Jupyter-based pytest plugins.
12+
13+
To use one of these plugins, you'll also need to install their dependencies. This requires a second `pip install` call. For example, if you'd like to use the `jupyter_server` plugin, you'll need to call:
14+
```bash
15+
pip install "pytest-jupyter[server]"
16+
```
17+
This *should* install everything you need for the plugin to work.
18+
19+
To use a plugin, add it to the `pytest_plugins` list in the `conftest.py` of your project's root test directory.
20+
```python
21+
# inside the conftest.py
22+
23+
pytest_plugins = ["pytest_jupyter.jupyter_server"]
24+
```
25+
All fixtures inside the plugin (e.g. jupyter_server) will be available to all of your project's unit tests. You can use a fixtures by passing it as an argument to your unit test function:
26+
```python
27+
async def test_jupyter_server_api(jp_fetch):
28+
# Send request to a temporary Jupyter Server Web Application
29+
response = await jp_fetch("api/spec.yml")
30+
31+
# Confirm that the request is successful.
32+
assert response.code == 200
33+
```
34+
35+
You can list the fixtures for a given plugin using the `--fixtures` argument from the pytest command line interface:
36+
```bash
37+
pytest --fixtures -p pytest_jupyter.jupyter_server
38+
```
39+
or by calling the `pytest --fixtures` where the plugin is listed in the `pytest_plugins` variable of a given test directory.

docs/index.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@ A set of [pytest plugins](https://docs.pytest.org/en/stable/plugins.html) for Ju
44

55
## Basic Usage
66

7-
Install `pytest-jupyter` from PyPI using pip:
8-
```
7+
First, install `pytest-jupyter` from PyPI using pip:
8+
```bash
99
pip install pytest-jupyter
1010
```
11+
This installs the basic pytest-jupyter package that insludes fixture definitions for the various Jupyter-based pytest plugins.
1112

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+
To use one of these plugins, you'll also need to install their dependencies. This requires a second `pip install` call. For example, if you'd like to use the `jupyter_server` plugin, you'll need to call:
14+
```bash
15+
pip install "pytest-jupyter[server]"
16+
```
17+
This *should* install everything you need for the plugin to work.
1318

19+
To use a plugin, add it to the `pytest_plugins` list in the `conftest.py` of your project's root test directory.
20+
```python
21+
# inside the conftest.py
22+
23+
pytest_plugins = ["pytest_jupyter.jupyter_server"]
24+
```
25+
All fixtures inside the plugin (e.g. jupyter_server) will be available to all of your project's unit tests. You can use a fixtures by passing it as an argument to your unit test function:
1426
```python
1527
async def test_jupyter_server_api(jp_fetch):
1628
# Send request to a temporary Jupyter Server Web Application
@@ -20,6 +32,12 @@ async def test_jupyter_server_api(jp_fetch):
2032
assert response.code == 200
2133
```
2234

35+
You can list the fixtures for a given plugin using the `--fixtures` argument from the pytest command line interface:
36+
```bash
37+
pytest --fixtures -p pytest_jupyter.jupyter_server
38+
```
39+
or by calling the `pytest --fixtures` where the plugin is listed in the `pytest_plugins` variable of a given test directory.
40+
2341

2442
```{toctree}
2543
:maxdepth: 2

docs/plugins/jupyter_core.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Jupyter Core plugin
22

3-
The following fixtures are useful for setting up a test environment for Jupyter extensions and applications.
3+
The following plugin is useful for setting up a test environment for Jupyter extensions and applications.
4+
5+
To use this plugin, install the dependencies for this plugin:
6+
```
7+
pip install 'pytest-jupyter[core]'
8+
```
9+
and list the plugin in the `conftest.py` file at the root of your project's test directory.
410

511
## Fixtures
612

docs/plugins/jupyter_server.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22

33
The jupyter_server module provides fixtures for automatically setting-up/tearing-down Jupyter Servers.
44

5+
To use this plugin, install the dependencies for this plugin:
6+
```
7+
pip install 'pytest-jupyter[server]'
8+
```
9+
and list the plugin in the `conftest.py` file at the root of your project's test directory.
10+
511
You can make requests to a *test server* using the `jp_fetch` and `jp_ws_fetch` fixtures.
612

13+
714
## Fixtures
815

916
```{eval-rst}

pytest_jupyter/jupyter_core.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
3-
4-
import jupyter_core.paths
53
import os
64
import pytest
75
import sys
86

9-
from .utils import mkdir
7+
# The try block is needed so that the documentation can
8+
# still build without needed to install all the dependencies.
9+
try:
10+
import jupyter_core.paths
11+
12+
except (ModuleNotFoundError, ImportError) as e:
13+
import warnings
14+
warnings.warn(
15+
"The jupyter_core plugin has not been installed. "
16+
"If you're trying to use this plugin and you've installed "
17+
"`pytest-jupyter`, there is likely one more step "
18+
"you need. Try: `pip install 'pytest-jupyter[core]'`"
19+
)
1020

1121

22+
from .utils import mkdir
23+
1224
@pytest.fixture
1325
def jp_home_dir(tmp_path):
1426
"""Provides a temporary HOME directory value."""

pytest_jupyter/jupyter_server.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4-
import jupyter_core.paths
5-
import nbformat
64
import os
75
import json
86
import pytest
97
import shutil
10-
import tornado
118
import urllib.parse
129

1310
from binascii import hexlify
14-
from jupyter_server.extension import serverextension
15-
from jupyter_server.serverapp import ServerApp
16-
from jupyter_server.utils import url_path_join
17-
from jupyter_server.services.contents.filemanager import FileContentsManager
18-
from jupyter_server.services.contents.largefilemanager import LargeFileManager
19-
from tornado.escape import url_escape
20-
from traitlets.config import Config
11+
12+
# The try block is needed so that the documentation can
13+
# still build without needed to install all the dependencies.
14+
try:
15+
import tornado
16+
from tornado.escape import url_escape
17+
import jupyter_core.paths
18+
import nbformat
19+
from traitlets.config import Config
20+
21+
from jupyter_server.extension import serverextension
22+
from jupyter_server.serverapp import ServerApp
23+
from jupyter_server.utils import url_path_join
24+
from jupyter_server.services.contents.filemanager import FileContentsManager
25+
from jupyter_server.services.contents.largefilemanager import LargeFileManager
26+
27+
except (ModuleNotFoundError, ImportError) as e:
28+
import warnings
29+
warnings.warn(
30+
"The server plugin has not been installed. "
31+
"If you're trying to use this plugin and you've installed "
32+
"`pytest-jupyter`, there is likely one more step "
33+
"you need. Try: `pip install 'pytest-jupyter[server]'`"
34+
)
35+
2136

2237
from .utils import mkdir
2338

39+
# List of dependencies needed for this plugin.
40+
pytest_plugins = [
41+
"pytest_tornasync",
42+
"pytest_jupyter.jupyter_core"
43+
]
44+
45+
2446
# NOTE: This is a temporary fix for Windows 3.8
2547
# We have to override the io_loop fixture with an
2648
# asyncio patch. This will probably be removed in

setup.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,39 @@
1212
readme_path = HERE.joinpath('README.md')
1313
README = readme_path.read_text()
1414

15+
# Build the extra requirements for each plugin.
16+
EXTRA_REQUIRES = {
17+
'docs': [
18+
'Sphinx',
19+
'myst_parser',
20+
'pydata_sphinx_theme',
21+
],
22+
'core': [
23+
'jupyter_core'
24+
],
25+
'server': [
26+
'nbformat',
27+
'jupyter_core',
28+
'jupyter_server',
29+
'pytest-tornasync'
30+
]
31+
}
32+
1533
setup_args = dict(
1634
name=NAME,
1735
version=VERSION,
1836
description=DESCRIPTION,
1937
long_description=README,
2038
long_description_content_type='text/markdown',
21-
packages=find_packages(),
39+
packages=find_packages('.', exclude=['tests', 'tests.*']),
2240
author='Jupyter Development Team',
2341
author_email='[email protected]',
2442
url='http://jupyter.org',
2543
license='BSD',
2644
platforms="Linux, Mac OS X, Windows",
2745
keywords=['Jupyter', 'pytest'],
28-
install_requires=[
29-
'traitlets',
30-
'tornado',
31-
'pytest',
32-
'nbformat',
33-
'pytest-tornasync',
34-
'jupyter_core',
35-
'jupyter_server'
36-
],
37-
extras_require={
38-
'docs': ['Sphinx', 'myst_parser', 'pydata_sphinx_theme']
39-
},
40-
# the following makes a plugin available to pytest
41-
entry_points={
42-
"pytest11": [
43-
"pytest-jupyterserver = pytest_jupyter.jupyter_server",
44-
"pytest-jupytercore = pytest_jupyter.jupyter_core"
45-
]
46-
},
46+
install_requires=['pytest'],
47+
extras_require=EXTRA_REQUIRES,
4748
# custom PyPI classifier for pytest plugins
4849
classifiers=["Framework :: Pytest"],
4950
)

0 commit comments

Comments
 (0)