Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up handling of tests #700

Merged
merged 14 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
pip check
- name: Run the tests
run: |
pytest -vv --integration_tests=true jupyter_server
pytest -vv --integration_tests=true tests
15 changes: 11 additions & 4 deletions .github/workflows/python-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ jobs:
- name: Run the tests
if: ${{ matrix.python-version != 'pypy-3.7' }}
run: |
pytest -vv jupyter_server --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered
pytest -vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered
- name: Run the tests on pypy
if: ${{ matrix.python-version == 'pypy-3.7' }}
run: |
pytest -vv jupyter_server
pytest -vv
- name: Install the Python dependencies for the examples
run: |
cd examples/simple && pip install -e .
Expand Down Expand Up @@ -99,7 +99,14 @@ jobs:
uses: actions/download-artifact@v2
- name: Install From SDist
run: |
pip install --find-links=./sdist "jupyter_server[test]>=0.0.dev0"
set -ex
cd sdist
mkdir test
tar --strip-components=1 -zxvf jupyter_server* -C ./test
cd test
pip install -e .[test]
pip install pytest-github-actions-annotate-failures
- name: Run Test
run: pytest -vv --pyargs --timeout=300 --timeout_method=thread jupyter_server --capture=no
run: |
cd sdist/test
pytest -vv
4 changes: 2 additions & 2 deletions .github/workflows/python-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:
- name: Run the tests
if: ${{ !startsWith( matrix.python-version, 'pypy' ) }}
run: |
pytest -vv jupyter_server --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered
pytest -vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered
- name: Run the tests on pypy
if: ${{ startsWith( matrix.python-version, 'pypy' ) }}
run: |
pytest -vv jupyter_server
pytest -vv
- name: Install the Python dependencies for the examples
run: |
cd examples/simple && pip install -e .
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
# the file descriptions opened by the asyncio IOLoop.
# This leads to a nasty, flaky race condition that we haven't
# been able to solve.
pytest -vv -s jupyter_server
pytest -vv -s
- name: Install the Python dependencies for the examples
run: |
cd examples/simple && pip install -e .
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Install dependencies::

To run the Python tests, use::

pytest jupyter_server
pytest
pytest examples/simple # to test the examples

Building the Docs
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ include CONTRIBUTING.rst
include README.md
include RELEASE.md
include CHANGELOG.md
include setupbase.py
include package.json

# include everything in package_data
recursive-include jupyter_server *
recursive-include tests *

# Documentation
graft docs
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from jupyter_server.conftest import * # noqa
pytest_plugins = ["jupyter_server.pytest_plugin"]
31 changes: 0 additions & 31 deletions jupyter_server/conftest.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ignore = ["tbump.toml", ".*", "*.yml", "package-lock.json", "bootstrap*", "conft
[tool.pytest.ini_options]
addopts = "--doctest-modules"
testpaths = [
"jupyter_server/"
"tests/"
]
timeout = 300
timeout_method = "thread"
Expand Down
6 changes: 5 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ console_scripts =
jupyter-server = jupyter_server.serverapp:main

[options.packages.find]
exclude = ['docs*', 'examples*']
exclude =
docs.*
examples.*
tests
tests.*

[flake8]
ignore = E, C, W, F403, F811, F841, E402, I100, I101, D400
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 31 additions & 1 deletion jupyter_server/tests/extension/conftest.py → tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
import pytest

from .mockextensions.app import MockExtensionApp
from tests.extension.mockextensions.app import MockExtensionApp


pytest_plugins = ["jupyter_server.pytest_plugin"]


def pytest_addoption(parser):
parser.addoption(
"--integration_tests",
default=False,
type=bool,
help="only run tests with the 'integration_test' pytest mark.",
)


def pytest_configure(config):
# register an additional marker
config.addinivalue_line("markers", "integration_test")


def pytest_runtest_setup(item):
is_integration_test = any(mark for mark in item.iter_markers(name="integration_test"))

if item.config.getoption("--integration_tests") is True:
if not is_integration_test:
pytest.skip("Only running tests marked as 'integration_test'.")
else:
if is_integration_test:
pytest.skip(
"Skipping this test because it's marked 'integration_test'. Run integration tests using the `--integration_tests` flag."
)


mock_html = """
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
def _jupyter_server_extension_points():
return [
{
"module": "jupyter_server.tests.extension.mockextensions.app",
"module": "tests.extension.mockextensions.app",
"app": MockExtensionApp,
},
{"module": "jupyter_server.tests.extension.mockextensions.mock1"},
{"module": "jupyter_server.tests.extension.mockextensions.mock2"},
{"module": "jupyter_server.tests.extension.mockextensions.mock3"},
{"module": "tests.extension.mockextensions.mock1"},
{"module": "tests.extension.mockextensions.mock2"},
{"module": "tests.extension.mockextensions.mock3"},
]
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ class MockExtensionApp(ExtensionAppJinjaMixin, ExtensionApp):
mock_trait = Unicode("mock trait", config=True)
loaded = False

serverapp_config = {
"jpserver_extensions": {"jupyter_server.tests.extension.mockextensions.mock1": True}
}
serverapp_config = {"jpserver_extensions": {"tests.extension.mockextensions.mock1": True}}

@staticmethod
def get_extension_package():
return "jupyter_server.tests.extension.mockextensions"
return "tests.extension.mockextensions"

def initialize_handlers(self):
self.handlers.append(("/mock", MockExtensionHandler))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
# by the test functions.
def _jupyter_server_extension_paths():
return [{"module": "jupyter_server.tests.extension.mockextensions.mock1"}]
return [{"module": "tests.extension.mockextensions.mock1"}]


def _load_jupyter_server_extension(serverapp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
# by the test functions.
def _jupyter_server_extension_paths():
return [{"module": "jupyter_server.tests.extension.mockextensions.mock2"}]
return [{"module": "tests.extension.mockextensions.mock2"}]


def _load_jupyter_server_extension(serverapp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Function that makes these extensions discoverable
# by the test functions.
def _jupyter_server_extension_paths():
return [{"module": "jupyter_server.tests.extension.mockextensions.mockext_both"}]
return [{"module": "tests.extension.mockextensions.mockext_both"}]


def _load_jupyter_server_extension(serverapp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Function that makes these extensions discoverable
# by the test functions.
def _jupyter_server_extension_paths():
return [{"module": "jupyter_server.tests.extension.mockextensions.mockext_py"}]
return [{"module": "tests.extension.mockextensions.mockext_py"}]


def _load_jupyter_server_extension(serverapp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Function that makes these extensions discoverable
# by the test functions.
def _jupyter_server_extension_paths():
return [{"module": "jupyter_server.tests.extension.mockextensions.mockext_sys"}]
return [{"module": "tests.extension.mockextensions.mockext_sys"}]


def _load_jupyter_server_extension(serverapp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Function that makes these extensions discoverable
# by the test functions.
def _jupyter_server_extension_paths():
return [{"module": "jupyter_server.tests.extension.mockextensions.mockext_user"}]
return [{"module": "tests.extension.mockextensions.mockext_user"}]


def _load_jupyter_server_extension(serverapp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def jp_server_config(jp_template_dir):
config = {
"ServerApp": {
"jpserver_extensions": {"jupyter_server.tests.extension.mockextensions": True},
"jpserver_extensions": {"tests.extension.mockextensions": True},
},
"MockExtensionApp": {
"template_paths": [str(jp_template_dir)],
Expand All @@ -22,7 +22,7 @@ def jp_server_config(jp_template_dir):

@pytest.fixture
def mock_extension(extension_manager):
name = "jupyter_server.tests.extension.mockextensions"
name = "tests.extension.mockextensions"
pkg = extension_manager.extensions[name]
point = pkg.extension_points["mockextension"]
app = point.app
Expand Down Expand Up @@ -115,12 +115,12 @@ def test_browser_open(monkeypatch, jp_environ, config, expected_value):
def test_load_parallel_extensions(monkeypatch, jp_environ):
serverapp = MockExtensionApp.initialize_server()
exts = serverapp.extension_manager.extensions
assert "jupyter_server.tests.extension.mockextensions.mock1" in exts
assert "jupyter_server.tests.extension.mockextensions" in exts
assert "tests.extension.mockextensions.mock1" in exts
assert "tests.extension.mockextensions" in exts

exts = serverapp.jpserver_extensions
assert exts["jupyter_server.tests.extension.mockextensions.mock1"]
assert exts["jupyter_server.tests.extension.mockextensions"]
assert exts["tests.extension.mockextensions.mock1"]
assert exts["tests.extension.mockextensions"]


def test_stop_extension(jp_serverapp, caplog):
Expand All @@ -132,7 +132,7 @@ def test_stop_extension(jp_serverapp, caplog):

# load extensions (make sure we only have the one extension loaded
jp_serverapp.extension_manager.load_all_extensions()
extension_name = "jupyter_server.tests.extension.mockextensions"
extension_name = "tests.extension.mockextensions"
assert list(jp_serverapp.extension_manager.extension_apps) == [extension_name]

# add a stop_extension method for the extension app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
@pytest.fixture
def jp_server_config(jp_template_dir):
return {
"ServerApp": {
"jpserver_extensions": {"jupyter_server.tests.extension.mockextensions": True}
},
"ServerApp": {"jpserver_extensions": {"tests.extension.mockextensions": True}},
"MockExtensionApp": {"template_paths": [str(jp_template_dir)]},
}

Expand All @@ -26,9 +24,7 @@ async def test_handler_template(jp_fetch, mock_template):
"jp_server_config",
[
{
"ServerApp": {
"jpserver_extensions": {"jupyter_server.tests.extension.mockextensions": True}
},
"ServerApp": {"jpserver_extensions": {"tests.extension.mockextensions": True}},
"MockExtensionApp": {
# Change a trait in the MockExtensionApp using
# the following config value.
Expand Down Expand Up @@ -58,7 +54,7 @@ async def test_handler_argv(jp_fetch, jp_argv):
(
{
"ServerApp": {
"jpserver_extensions": {"jupyter_server.tests.extension.mockextensions": True},
"jpserver_extensions": {"tests.extension.mockextensions": True},
# Move extension handlers behind a url prefix
"base_url": "test_prefix",
},
Expand Down
Loading