From 86548aefa6505e717d9f6261aef4b693e8673bb2 Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Fri, 11 Jun 2021 13:36:20 +0100 Subject: [PATCH 1/5] actions: use setup.cfg as the cache key * the dependencies are specified in setup.cfg rather than .py --- .github/workflows/integration-tests.yml | 2 +- .github/workflows/python-linux.yml | 2 +- .github/workflows/python-macos.yml | 2 +- .github/workflows/python-windows.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 9a4c03f038..a12a3d0301 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -31,7 +31,7 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.pip-cache.outputs.dir }} - key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }} + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.cfg') }} restore-keys: | ${{ runner.os }}-pip-${{ matrix.python-version }}- ${{ runner.os }}-pip- diff --git a/.github/workflows/python-linux.yml b/.github/workflows/python-linux.yml index eed4081e39..233ea75190 100644 --- a/.github/workflows/python-linux.yml +++ b/.github/workflows/python-linux.yml @@ -31,7 +31,7 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.pip-cache.outputs.dir }} - key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }} + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.cfg') }} restore-keys: | ${{ runner.os }}-pip-${{ matrix.python-version }}- ${{ runner.os }}-pip- diff --git a/.github/workflows/python-macos.yml b/.github/workflows/python-macos.yml index 163e74a525..4fad04f11f 100644 --- a/.github/workflows/python-macos.yml +++ b/.github/workflows/python-macos.yml @@ -31,7 +31,7 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.pip-cache.outputs.dir }} - key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }} + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.cfg') }} restore-keys: | ${{ runner.os }}-pip-${{ matrix.python-version }}- ${{ runner.os }}-pip- diff --git a/.github/workflows/python-windows.yml b/.github/workflows/python-windows.yml index 525aa9d7ed..2735513af8 100644 --- a/.github/workflows/python-windows.yml +++ b/.github/workflows/python-windows.yml @@ -31,7 +31,7 @@ jobs: uses: actions/cache@v1 with: path: ${{ steps.pip-cache.outputs.dir }} - key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }} + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.cfg') }} restore-keys: | ${{ runner.os }}-pip-${{ matrix.python-version }}- ${{ runner.os }}-pip- From a4d22e80497ae75de4dc9d04652b8d77bc21713d Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Fri, 11 Jun 2021 16:55:48 +0100 Subject: [PATCH 2/5] tests: compatibility with pytest>=4 * fix defining pytest_plugins in non-top-level conftest file (pytest 3+) https://docs.pytest.org/en/6.2.x/deprecations.html#pytest-plugins-in-non-top-level-conftest-files * update to pytest 6 as this was the first version to support pyproject.toml https://docs.pytest.org/en/stable/changelog.html#id123 --- .github/workflows/downstream.yml | 6 +++++- .github/workflows/integration-tests.yml | 2 +- .github/workflows/python-linux.yml | 6 +++--- .github/workflows/python-macos.yml | 6 +++--- .github/workflows/python-windows.yml | 4 ++-- CONTRIBUTING.rst | 2 ++ README.md | 5 +---- jupyter_server/tests/conftest.py => conftest.py | 5 +---- examples/simple/tests/conftest.py | 3 --- pyproject.toml | 2 +- setup.cfg | 12 +++++++++++- 11 files changed, 30 insertions(+), 23 deletions(-) rename jupyter_server/tests/conftest.py => conftest.py (88%) delete mode 100644 examples/simple/tests/conftest.py diff --git a/.github/workflows/downstream.yml b/.github/workflows/downstream.yml index 0007b252d3..dbef7cde58 100644 --- a/.github/workflows/downstream.yml +++ b/.github/workflows/downstream.yml @@ -9,6 +9,7 @@ on: jobs: tests: runs-on: ubuntu-latest + timeout-minutes: 15 steps: - name: Checkout @@ -22,11 +23,14 @@ jobs: - name: Install dependencies run: | pip install --upgrade pip - pip install ".[test]" + pip install "." pip install --pre --upgrade jupyterlab_server[test] jupyterlab[test] nbclassic[test] pip freeze - name: Run tests + working-directory: ../ run: | + # NOTE: tests won't pass from inside the working copy because of + # conftest.py:pytest_plugins (must be at the top level) pytest --pyargs jupyterlab_server python -m jupyterlab.browser_check --no-browser-test diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index a12a3d0301..cc3188bd4b 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -44,4 +44,4 @@ jobs: pip check - name: Run the tests run: | - pytest -vv --integration_tests jupyter_server + pytest -vv --integration_tests=true diff --git a/.github/workflows/python-linux.yml b/.github/workflows/python-linux.yml index 233ea75190..ca2c656e05 100644 --- a/.github/workflows/python-linux.yml +++ b/.github/workflows/python-linux.yml @@ -45,17 +45,17 @@ jobs: - name: Run the tests if: ${{ matrix.python-version != 'pypy3' }} 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 == 'pypy3' }} run: | - pytest -vv jupyter_server + pytest -vv - name: Install the Python dependencies for the examples run: | cd examples/simple && pip install -e . - name: Run the tests for the examples run: | - pytest examples/simple/tests/test_handlers.py + pytest examples/simple/tests/test_handlers.py --confcutdir=$PWD - name: Coverage if: ${{ matrix.python-version != 'pypy3' }} run: | diff --git a/.github/workflows/python-macos.yml b/.github/workflows/python-macos.yml index 4fad04f11f..7339751c8e 100644 --- a/.github/workflows/python-macos.yml +++ b/.github/workflows/python-macos.yml @@ -45,17 +45,17 @@ jobs: - name: Run the tests if: ${{ matrix.python-version != 'pypy3' }} 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 == 'pypy3' }} run: | - pytest -vv jupyter_server + pytest -vv - name: Install the Python dependencies for the examples run: | cd examples/simple && pip install -e . - name: Run the tests for the examples run: | - pytest examples/simple/tests/test_handlers.py + pytest examples/simple/tests/test_handlers.py --confcutdir=$PWD - name: Coverage if: ${{ matrix.python-version != 'pypy3' }} run: | diff --git a/.github/workflows/python-windows.yml b/.github/workflows/python-windows.yml index 2735513af8..b330c46258 100644 --- a/.github/workflows/python-windows.yml +++ b/.github/workflows/python-windows.yml @@ -49,10 +49,10 @@ 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 jupyter_server -s + pytest -vv -s - name: Install the Python dependencies for the examples run: | cd examples/simple && pip install -e . - name: Run the tests for the examples run: | - pytest examples/simple/tests/test_handlers.py + pytest examples/simple/tests/test_handlers.py --confcutdir=$PWD diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 6bdbc28330..6a32c279c6 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -58,10 +58,12 @@ Running Tests Install dependencies:: pip install -e .[test] + pip install -e examples/simple To run the Python tests, use:: pytest + pytest examples/simple Building the Docs ================= diff --git a/README.md b/README.md index cda88abf7d..e3ab6f4fd6 100644 --- a/README.md +++ b/README.md @@ -35,10 +35,7 @@ Launch with: ### Testing -To test an installed `jupyter_server`, run the following: - - pip install jupyter_server[test] - pytest jupyter_server +See [CONTRIBUTING](https://github.com/jupyter-server/jupyter_server/blob/master/CONTRIBUTING.rst#running-tests). ## Contributing diff --git a/jupyter_server/tests/conftest.py b/conftest.py similarity index 88% rename from jupyter_server/tests/conftest.py rename to conftest.py index 07dc30bb35..c461afc623 100644 --- a/jupyter_server/tests/conftest.py +++ b/conftest.py @@ -6,9 +6,6 @@ ] -import pytest - - def pytest_addoption(parser): parser.addoption( "--integration_tests", @@ -26,7 +23,7 @@ def pytest_configure(config): def pytest_runtest_setup(item): - is_integration_test = any([mark for mark in item.iter_markers(name="integration_test")]) + 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: diff --git a/examples/simple/tests/conftest.py b/examples/simple/tests/conftest.py deleted file mode 100644 index 87c6aff30a..0000000000 --- a/examples/simple/tests/conftest.py +++ /dev/null @@ -1,3 +0,0 @@ -pytest_plugins = [ - 'jupyter_server.pytest_plugin' -] diff --git a/pyproject.toml b/pyproject.toml index 9b4b236a15..f449f97195 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "jupyter_packaging.build_api" factory = "jupyter_packaging.npm_builder" [tool.check-manifest] -ignore = ["tbump.toml", ".*", "*.yml", "package-lock.json", "bootstrap*"] +ignore = ["tbump.toml", ".*", "*.yml", "package-lock.json", "bootstrap*", "conftest.py"] [tool.pytest.ini_options] # Exclude the example tests. diff --git a/setup.cfg b/setup.cfg index 552401894c..07572b147a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -45,7 +45,17 @@ install_requires = requests-unixsocket [options.extras_require] -test = coverage; pytest; pytest-cov; pytest-mock; requests; pytest-tornasync; pytest-console-scripts; ipykernel +test = + coverage + pytest>=6.0 + pytest-cov + pytest-mock + requests + pytest-tornasync + pytest-console-scripts + ipykernel + # NOTE: we cannot auto install examples/simple here because of: + # https://github.com/pypa/pip/issues/6658 [options.entry_points] console_scripts = From 630b5249ac2d6c5c46a86161b1834b1215503c9d Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Fri, 11 Jun 2021 18:10:43 +0100 Subject: [PATCH 3/5] tests: run doctests --- jupyter_server/auth/security.py | 10 +++++----- jupyter_server/traittypes.py | 10 ++++++---- pyproject.toml | 6 ++++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/jupyter_server/auth/security.py b/jupyter_server/auth/security.py index 833726d775..4e630c4daa 100644 --- a/jupyter_server/auth/security.py +++ b/jupyter_server/auth/security.py @@ -43,8 +43,8 @@ def passwd(passphrase=None, algorithm='argon2'): Examples -------- - >>> passwd('mypassword') - 'sha1:7cf3:b7d6da294ea9592a9480c8f52e63cd42cfb9dd12' + >>> passwd('mypassword') # doctest: +ELLIPSIS + 'argon2:...' """ if passphrase is None: @@ -94,11 +94,11 @@ def passwd_check(hashed_passphrase, passphrase): Examples -------- - >>> from jupyter_server.auth.security import passwd_check - >>> passwd_check('argon2:...', 'mypassword') + >>> myhash = passwd('mypassword') + >>> passwd_check(myhash, 'mypassword') True - >>> passwd_check('argon2:...', 'otherpassword') + >>> passwd_check(myhash, 'otherpassword') False >>> passwd_check('sha1:0e112c3ddfce:a68df677475c2b47b6e86d0467eec97ac5f4b85a', diff --git a/jupyter_server/traittypes.py b/jupyter_server/traittypes.py index 8e8cb3b3ff..9f31232197 100644 --- a/jupyter_server/traittypes.py +++ b/jupyter_server/traittypes.py @@ -50,13 +50,15 @@ class name where an object was defined. 'an object' >>> describe("a", type(object)) 'a type' + Definite description: - >>> describe("the", object()) - "the object at '0x10741f1b0'" + >>> describe("the", object()) # doctest: +ELLIPSIS + "the object at '0x...'" >>> describe("the", object) - "the type 'object'" + 'the object object' >>> describe("the", type(object)) - "the type 'type'" + 'the type type' + Definitely named description: >>> describe("the", object(), "I made") 'the object I made' diff --git a/pyproject.toml b/pyproject.toml index f449f97195..6c93f021e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,8 +9,10 @@ factory = "jupyter_packaging.npm_builder" ignore = ["tbump.toml", ".*", "*.yml", "package-lock.json", "bootstrap*", "conftest.py"] [tool.pytest.ini_options] -# Exclude the example tests. -norecursedirs = "examples/*" +addopts = "--doctest-modules" +testpaths = [ + "jupyter_server" +] [tool.tbump.version] current = "1.10.0.dev0" From 27f011ebc8dd80389a7abf292110bc6c3e29da63 Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Wed, 7 Jul 2021 15:17:45 +0100 Subject: [PATCH 4/5] actions: run tests against development versions of python --- .github/workflows/integration-tests.yml | 2 +- .github/workflows/python-linux.yml | 2 +- .github/workflows/python-macos.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index cc3188bd4b..39ec2da9be 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: os: [ubuntu] - python-version: [ '3.6', '3.7', '3.8', '3.9', 'pypy3' ] + python-version: [ '3.6', '3.7', '3.8', '3.9', '3.10-dev', 'pypy3' ] steps: - name: Checkout uses: actions/checkout@v1 diff --git a/.github/workflows/python-linux.yml b/.github/workflows/python-linux.yml index ca2c656e05..ea289c87c4 100644 --- a/.github/workflows/python-linux.yml +++ b/.github/workflows/python-linux.yml @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: os: [ubuntu] - python-version: [ '3.6', '3.7', '3.8', '3.9', 'pypy3' ] + python-version: [ '3.6', '3.7', '3.8', '3.9', '3.10-dev', 'pypy3' ] steps: - name: Checkout uses: actions/checkout@v1 diff --git a/.github/workflows/python-macos.yml b/.github/workflows/python-macos.yml index 7339751c8e..5ff6bae328 100644 --- a/.github/workflows/python-macos.yml +++ b/.github/workflows/python-macos.yml @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: os: [macos] - python-version: [ '3.6', '3.7', '3.8', '3.9', 'pypy3' ] + python-version: [ '3.6', '3.7', '3.8', '3.9', '3.10-dev', 'pypy3' ] steps: - name: Checkout uses: actions/checkout@v1 From 5320209173b0490899a2e59c22767b16d19082bd Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Wed, 7 Jul 2021 15:31:41 +0100 Subject: [PATCH 5/5] actions: bump action versions --- .github/workflows/integration-tests.yml | 6 +++--- .github/workflows/python-linux.yml | 6 +++--- .github/workflows/python-macos.yml | 6 +++--- .github/workflows/python-windows.yml | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 39ec2da9be..3f1d410511 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -14,9 +14,9 @@ jobs: python-version: [ '3.6', '3.7', '3.8', '3.9', '3.10-dev', 'pypy3' ] steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Install Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} architecture: 'x64' @@ -28,7 +28,7 @@ jobs: run: | echo "::set-output name=dir::$(pip cache dir)" - name: Cache pip - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ${{ steps.pip-cache.outputs.dir }} key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.cfg') }} diff --git a/.github/workflows/python-linux.yml b/.github/workflows/python-linux.yml index ea289c87c4..b57ecf0463 100644 --- a/.github/workflows/python-linux.yml +++ b/.github/workflows/python-linux.yml @@ -14,9 +14,9 @@ jobs: python-version: [ '3.6', '3.7', '3.8', '3.9', '3.10-dev', 'pypy3' ] steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Install Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} architecture: 'x64' @@ -28,7 +28,7 @@ jobs: run: | echo "::set-output name=dir::$(pip cache dir)" - name: Cache pip - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ${{ steps.pip-cache.outputs.dir }} key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.cfg') }} diff --git a/.github/workflows/python-macos.yml b/.github/workflows/python-macos.yml index 5ff6bae328..b5b5e07e7b 100644 --- a/.github/workflows/python-macos.yml +++ b/.github/workflows/python-macos.yml @@ -14,9 +14,9 @@ jobs: python-version: [ '3.6', '3.7', '3.8', '3.9', '3.10-dev', 'pypy3' ] steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Install Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} architecture: 'x64' @@ -28,7 +28,7 @@ jobs: run: | echo "::set-output name=dir::$(pip cache dir)" - name: Cache pip - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ${{ steps.pip-cache.outputs.dir }} key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.cfg') }} diff --git a/.github/workflows/python-windows.yml b/.github/workflows/python-windows.yml index b330c46258..0a8d68f231 100644 --- a/.github/workflows/python-windows.yml +++ b/.github/workflows/python-windows.yml @@ -14,9 +14,9 @@ jobs: python-version: [ '3.6', '3.7', '3.8', '3.9' ] steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Install Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} architecture: 'x64' @@ -28,7 +28,7 @@ jobs: run: | echo "::set-output name=dir::$(pip cache dir)" - name: Cache pip - uses: actions/cache@v1 + uses: actions/cache@v2 with: path: ${{ steps.pip-cache.outputs.dir }} key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.cfg') }}