diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8086979..56af1e1 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 -- --with-integration-tests typecheck: runs-on: ubuntu-latest diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1cc7000..ed7e36e 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 -- --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 0000000..3d0ff4a --- /dev/null +++ b/noxfile.py @@ -0,0 +1,36 @@ +# 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, env={"EDOT_IN_NOX": "1"}) + + +@nox.session +def tests(session): + run_tests(session, pytest_extra_args=session.posargs)