From 15406a4d5d910766fb88947608a9ff7a271ebd7b Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 17 Oct 2025 11:40:32 +0200 Subject: [PATCH 1/4] Run tests under nox So we can test the entrypoints we define. --- .github/workflows/ci.yml | 7 ++----- CONTRIBUTING.md | 13 +++++++------ noxfile.py | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 noxfile.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8086979c..363e9f14 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,11 +81,8 @@ jobs: with: python-version: ${{ env[matrix.python-version] }} architecture: "x64" - - run: pip install -r dev-requirements.txt - - name: run recorded tests with python 3.10+ where urllib3 2.x is supported - run: pip install pytest-vcr - if: ${{ matrix.python-version != 'py39' }} - - run: pytest --with-integration-tests + - run: pip install nox + - run: nox -s with_integration_tests typecheck: runs-on: ubuntu-latest diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1cc70002..44e53171 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -75,10 +75,14 @@ Once your changes are ready to submit for review: ### Testing -To run local unit tests, you can install requirements and then run `pytest` from the project root: +To run local unit tests, you can install nox and then run `nox` from the project root: - pip install -r dev-requirements.txt - pytest + pip install nox + nox + +To run also the slower integration tests you can run: + + nox -s with_integration_tests Pytest will automatically discover tests. @@ -91,9 +95,6 @@ dynamic discovery features. In particular, and hard to discover, due to the fact that they do not need to be imported to be used. -By default only unit tests are run because tests under `tests/integrations` are a bit slower. -Use `pytest --with-integration-tests` to run them. - ### Workflow All feature development and most bug fixes hit the main branch first. diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 00000000..4394b1d3 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,41 @@ +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +# or more contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import nox +import sys + + +def run_tests(session: nox.Session, pytest_extra_args: list[str] = []): + python_version = (sys.version_info.major, sys.version_info.minor, sys.version_info.micro) + vcrpy_is_supported = python_version >= (3, 10, 0) + + session.install("-r", "dev-requirements.txt") + if vcrpy_is_supported: + session.install("pytest-vcr") + # install the package for being able to use the entry points we define + session.install("-e", ".") + + session.run("pytest", *pytest_extra_args) + + +@nox.session +def tests(session): + run_tests(session) + + +@nox.session(default=False) +def with_integration_tests(session): + run_tests(session, ["--with-integration-tests"]) From 24b745007e9ba99a99feb1547db71ce620f9a1c7 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 17 Oct 2025 11:56:20 +0200 Subject: [PATCH 2/4] Set an environment variable so that tests knows they are run in nox --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 4394b1d3..bcb2f42a 100644 --- a/noxfile.py +++ b/noxfile.py @@ -28,7 +28,7 @@ def run_tests(session: nox.Session, pytest_extra_args: list[str] = []): # install the package for being able to use the entry points we define session.install("-e", ".") - session.run("pytest", *pytest_extra_args) + session.run("pytest", *pytest_extra_args, env={"EDOT_IN_NOX": "1"}) @nox.session From bad9195b9fee7dca2880213041cc1fdc8a77f6ca Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 17 Oct 2025 12:13:57 +0200 Subject: [PATCH 3/4] Pass posargs instead of creating an integration tests session --- CONTRIBUTING.md | 2 +- noxfile.py | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 44e53171..ed7e36e7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -82,7 +82,7 @@ To run local unit tests, you can install nox and then run `nox` from the project To run also the slower integration tests you can run: - nox -s with_integration_tests + nox -- --with-integration-tests Pytest will automatically discover tests. diff --git a/noxfile.py b/noxfile.py index bcb2f42a..3d0ff4aa 100644 --- a/noxfile.py +++ b/noxfile.py @@ -33,9 +33,4 @@ def run_tests(session: nox.Session, pytest_extra_args: list[str] = []): @nox.session def tests(session): - run_tests(session) - - -@nox.session(default=False) -def with_integration_tests(session): - run_tests(session, ["--with-integration-tests"]) + run_tests(session, pytest_extra_args=session.posargs) From 87c817939da5a243d99b0ebd904df6634c689df5 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Fri, 17 Oct 2025 12:17:42 +0200 Subject: [PATCH 4/4] update workflows --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 363e9f14..56af1e1d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,7 @@ jobs: python-version: ${{ env[matrix.python-version] }} architecture: "x64" - run: pip install nox - - run: nox -s with_integration_tests + - run: nox -- --with-integration-tests typecheck: runs-on: ubuntu-latest