Skip to content

Commit 7738d00

Browse files
authored
Merge pull request jupyter-server#335 from kevin-bates/remove-pytest-plugins
Switch fixtures to use those in pytest-jupyter to avoid collisions
2 parents c52c020 + 39cc7e0 commit 7738d00

28 files changed

+423
-448
lines changed

setup.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@
5151
"pywin32>=1.0 ; sys_platform == 'win32'"
5252
],
5353
extras_require = {
54-
'test': ['nose', 'coverage', 'requests', 'nose_warnings_filters',
55-
'pytest', 'pytest-cov', 'pytest-tornasync',
54+
'test': ['coverage', 'requests',
55+
'pytest', 'pytest-cov', 'pytest-jupyter',
5656
'pytest-console-scripts', 'ipykernel'],
57-
'test:sys_platform == "win32"': ['nose-exclude'],
5857
},
5958
python_requires = '>=3.6',
6059
entry_points = {

tests/conftest.py

-1
This file was deleted.

tests/extension/conftest.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626

2727

2828
@pytest.fixture
29-
def mock_template(template_dir):
30-
index = template_dir.joinpath('index.html')
29+
def mock_template(jp_template_dir):
30+
index = jp_template_dir.joinpath('index.html')
3131
index.write_text(mock_html)
3232

3333

3434
@pytest.fixture
35-
def extension_manager(serverapp):
36-
return serverapp.extension_manager
35+
def extension_manager(jp_serverapp):
36+
return jp_serverapp.extension_manager
3737

3838

3939
@pytest.fixture
40-
def config_file(config_dir):
40+
def config_file(jp_config_dir):
4141
""""""
42-
f = config_dir.joinpath("jupyter_mockextension_config.py")
42+
f = jp_config_dir.joinpath("jupyter_mockextension_config.py")
4343
f.write_text("c.MockExtensionApp.mock_trait ='config from file'")
4444
return f

tests/extension/test_app.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
@pytest.fixture
6-
def server_config(template_dir):
6+
def jp_server_config(jp_template_dir):
77
config = {
88
"ServerApp": {
99
"jpserver_extensions": {
@@ -12,7 +12,7 @@ def server_config(template_dir):
1212
},
1313
"MockExtensionApp": {
1414
"template_paths": [
15-
str(template_dir)
15+
str(jp_template_dir)
1616
],
1717
"log_level": 'DEBUG'
1818
}
@@ -29,40 +29,41 @@ def mock_extension(extension_manager):
2929
return app
3030

3131

32-
def test_initialize(serverapp, template_dir, mock_extension):
32+
def test_initialize(jp_serverapp, jp_template_dir, mock_extension):
3333
# Check that settings and handlers were added to the mock extension.
3434
assert isinstance(mock_extension.serverapp, ServerApp)
3535
assert len(mock_extension.handlers) > 0
3636
assert mock_extension.loaded
37-
assert mock_extension.template_paths == [str(template_dir)]
37+
assert mock_extension.template_paths == [str(jp_template_dir)]
3838

3939

4040
@pytest.mark.parametrize(
41-
'trait_name, trait_value, argv',
41+
'trait_name, trait_value, jp_argv',
4242
(
4343
[
4444
'mock_trait',
4545
'test mock trait',
46-
['--MockExtensionApp.mock_trait="test mock trait"']
46+
['--MockExtensionApp.mock_trait=test mock trait']
4747
],
4848
)
4949
)
5050
def test_instance_creation_with_argv(
5151
trait_name,
5252
trait_value,
53+
jp_argv,
5354
mock_extension,
5455
):
5556
assert getattr(mock_extension, trait_name) == trait_value
5657

5758

5859
def test_extensionapp_load_config_file(
5960
config_file,
60-
serverapp,
61+
jp_serverapp,
6162
mock_extension,
6263
):
6364
# Assert default config_file_paths is the same in the app and extension.
64-
assert mock_extension.config_file_paths == serverapp.config_file_paths
65-
assert mock_extension.config_dir == serverapp.config_dir
65+
assert mock_extension.config_file_paths == jp_serverapp.config_file_paths
66+
assert mock_extension.config_dir == jp_serverapp.config_dir
6667
assert mock_extension.config_file_name == 'jupyter_mockextension_config'
6768
# Assert that the trait is updated by config file
6869
assert mock_extension.mock_trait == 'config from file'

tests/extension/test_config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
# Use ServerApps environment because it monkeypatches
99
# jupyter_core.paths and provides a config directory
1010
# that's not cross contaminating the user config directory.
11-
pytestmark = pytest.mark.usefixtures("environ")
11+
pytestmark = pytest.mark.usefixtures("jp_environ")
1212

1313

1414
@pytest.fixture
15-
def configd(env_config_path):
15+
def configd(jp_env_config_path):
1616
"""A pathlib.Path object that acts like a jupyter_server_config.d folder."""
17-
configd = env_config_path.joinpath('jupyter_server_config.d')
17+
configd = jp_env_config_path.joinpath('jupyter_server_config.d')
1818
configd.mkdir()
1919
return configd
2020

tests/extension/test_entrypoint.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pytestmark = pytest.mark.script_launch_mode('subprocess')
77

88

9-
def test_server_extension_list(environ, script_runner):
9+
def test_server_extension_list(jp_environ, script_runner):
1010
ret = script_runner.run(
1111
'jupyter',
1212
'server',

tests/extension/test_handler.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
@pytest.fixture
5-
def server_config(template_dir):
5+
def jp_server_config(jp_template_dir):
66
return {
77
"ServerApp": {
88
"jpserver_extensions": {
@@ -11,31 +11,31 @@ def server_config(template_dir):
1111
},
1212
"MockExtensionApp": {
1313
"template_paths": [
14-
str(template_dir)
14+
str(jp_template_dir)
1515
]
1616
}
1717
}
1818

1919

20-
async def test_handler(fetch):
21-
r = await fetch(
20+
async def test_handler(jp_fetch):
21+
r = await jp_fetch(
2222
'mock',
2323
method='GET'
2424
)
2525
assert r.code == 200
2626
assert r.body.decode() == 'mock trait'
2727

2828

29-
async def test_handler_template(fetch, mock_template):
30-
r = await fetch(
29+
async def test_handler_template(jp_fetch, mock_template):
30+
r = await jp_fetch(
3131
'mock_template',
3232
method='GET'
3333
)
3434
assert r.code == 200
3535

3636

3737
@pytest.mark.parametrize(
38-
'server_config',
38+
'jp_server_config',
3939
[
4040
{
4141
"ServerApp": {
@@ -51,9 +51,9 @@ async def test_handler_template(fetch, mock_template):
5151
}
5252
]
5353
)
54-
async def test_handler_setting(fetch):
54+
async def test_handler_setting(jp_fetch):
5555
# Test that the extension trait was picked up by the webapp.
56-
r = await fetch(
56+
r = await jp_fetch(
5757
'mock',
5858
method='GET'
5959
)
@@ -62,11 +62,11 @@ async def test_handler_setting(fetch):
6262

6363

6464
@pytest.mark.parametrize(
65-
'argv', (['--MockExtensionApp.mock_trait="test mock trait"'],)
65+
'jp_argv', (['--MockExtensionApp.mock_trait=test mock trait'],)
6666
)
67-
async def test_handler_argv(fetch):
67+
async def test_handler_argv(jp_fetch):
6868
# Test that the extension trait was picked up by the webapp.
69-
r = await fetch(
69+
r = await jp_fetch(
7070
'mock',
7171
method='GET'
7272
)
@@ -75,7 +75,7 @@ async def test_handler_argv(fetch):
7575

7676

7777
@pytest.mark.parametrize(
78-
'server_config',
78+
'jp_server_config',
7979
[
8080
{
8181
"ServerApp": {
@@ -93,17 +93,17 @@ async def test_handler_argv(fetch):
9393
}
9494
]
9595
)
96-
async def test_base_url(fetch):
96+
async def test_base_url(jp_fetch):
9797
# Test that the extension's handlers were properly prefixed
98-
r = await fetch(
98+
r = await jp_fetch(
9999
'test_prefix', 'mock',
100100
method='GET'
101101
)
102102
assert r.code == 200
103103
assert r.body.decode() == 'test mock trait'
104104

105105
# Test that the static namespace was prefixed by base_url
106-
r = await fetch(
106+
r = await jp_fetch(
107107
'test_prefix',
108108
'static', 'mockextension', 'mock.txt',
109109
method='GET'

tests/extension/test_manager.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Use ServerApps environment because it monkeypatches
1111
# jupyter_core.paths and provides a config directory
1212
# that's not cross contaminating the user config directory.
13-
pytestmark = pytest.mark.usefixtures("environ")
13+
pytestmark = pytest.mark.usefixtures("jp_environ")
1414

1515

1616
def test_extension_point_api():
@@ -76,9 +76,9 @@ def test_extension_manager_api():
7676
assert "tests.extension.mockextensions" in manager.extensions
7777

7878

79-
def test_extension_manager_linked_extensions(serverapp):
79+
def test_extension_manager_linked_extensions(jp_serverapp):
8080
name = "tests.extension.mockextensions"
8181
manager = ExtensionManager()
8282
manager.add_extension(name, enabled=True)
83-
manager.link_extension(name, serverapp)
83+
manager.link_extension(name, jp_serverapp)
8484
assert name in manager.linked_extensions

tests/extension/test_serverextension.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Use ServerApps environment because it monkeypatches
1313
# jupyter_core.paths and provides a config directory
1414
# that's not cross contaminating the user config directory.
15-
pytestmark = pytest.mark.usefixtures("environ")
15+
pytestmark = pytest.mark.usefixtures("jp_environ")
1616

1717

1818
def test_help_output():
@@ -29,13 +29,13 @@ def get_config(sys_prefix=True):
2929
return data.get("ServerApp", {}).get("jpserver_extensions", {})
3030

3131

32-
def test_enable(env_config_path, extension_environ):
32+
def test_enable(jp_env_config_path, jp_extension_environ):
3333
toggle_server_extension_python('mock1', True)
3434
config = get_config()
3535
assert config['mock1']
3636

3737

38-
def test_disable(env_config_path, extension_environ):
38+
def test_disable(jp_env_config_path, jp_extension_environ):
3939
toggle_server_extension_python('mock1', True)
4040
toggle_server_extension_python('mock1', False)
4141

@@ -44,9 +44,9 @@ def test_disable(env_config_path, extension_environ):
4444

4545

4646
def test_merge_config(
47-
env_config_path,
48-
configurable_serverapp,
49-
extension_environ
47+
jp_env_config_path,
48+
jp_configurable_serverapp,
49+
jp_extension_environ
5050
):
5151
# Toggle each extension module with a JSON config file
5252
# at the sys-prefix config dir.
@@ -80,8 +80,8 @@ def test_merge_config(
8080
)
8181

8282
# Enable the last extension, mockext_py, using the CLI interface.
83-
app = configurable_serverapp(
84-
config_dir=str(env_config_path),
83+
app = jp_configurable_serverapp(
84+
config_dir=str(jp_env_config_path),
8585
argv=[arg]
8686
)
8787
# Verify that extensions are enabled and merged in proper order.
@@ -94,7 +94,7 @@ def test_merge_config(
9494

9595

9696
@pytest.mark.parametrize(
97-
'server_config',
97+
'jp_server_config',
9898
[
9999
{
100100
"ServerApp": {
@@ -106,7 +106,7 @@ def test_merge_config(
106106
}
107107
]
108108
)
109-
def test_load_ordered(serverapp):
110-
assert serverapp.mockII is True, "Mock II should have been loaded"
111-
assert serverapp.mockI is True, "Mock I should have been loaded"
112-
assert serverapp.mock_shared == 'II', "Mock II should be loaded after Mock I"
109+
def test_load_ordered(jp_serverapp):
110+
assert jp_serverapp.mockII is True, "Mock II should have been loaded"
111+
assert jp_serverapp.mockI is True, "Mock I should have been loaded"
112+
assert jp_serverapp.mock_shared == 'II', "Mock II should be loaded after Mock I"

tests/extension/test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Use ServerApps environment because it monkeypatches
66
# jupyter_core.paths and provides a config directory
77
# that's not cross contaminating the user config directory.
8-
pytestmark = pytest.mark.usefixtures("environ")
8+
pytestmark = pytest.mark.usefixtures("jp_environ")
99

1010

1111
def test_validate_extension():

0 commit comments

Comments
 (0)