Skip to content

Commit 32fbeb9

Browse files
authored
Run tests under nox (#415)
* Run tests under nox So we can test the entrypoints we define. * Set an environment variable so that tests knows they are run in nox * Pass posargs instead of creating an integration tests session * update workflows
1 parent 94f5c2a commit 32fbeb9

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,8 @@ jobs:
8181
with:
8282
python-version: ${{ env[matrix.python-version] }}
8383
architecture: "x64"
84-
- run: pip install -r dev-requirements.txt
85-
- name: run recorded tests with python 3.10+ where urllib3 2.x is supported
86-
run: pip install pytest-vcr
87-
if: ${{ matrix.python-version != 'py39' }}
88-
- run: pytest --with-integration-tests
84+
- run: pip install nox
85+
- run: nox -- --with-integration-tests
8986

9087
typecheck:
9188
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,14 @@ Once your changes are ready to submit for review:
7575

7676
### Testing
7777

78-
To run local unit tests, you can install requirements and then run `pytest` from the project root:
78+
To run local unit tests, you can install nox and then run `nox` from the project root:
7979

80-
pip install -r dev-requirements.txt
81-
pytest
80+
pip install nox
81+
nox
82+
83+
To run also the slower integration tests you can run:
84+
85+
nox -- --with-integration-tests
8286

8387
Pytest will automatically discover tests.
8488

@@ -91,9 +95,6 @@ dynamic discovery features. In particular,
9195
and hard to discover, due to the fact that they do not need to be imported to
9296
be used.
9397

94-
By default only unit tests are run because tests under `tests/integrations` are a bit slower.
95-
Use `pytest --with-integration-tests` to run them.
96-
9798
### Workflow
9899

99100
All feature development and most bug fixes hit the main branch first.

noxfile.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
# or more contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import nox
18+
import sys
19+
20+
21+
def run_tests(session: nox.Session, pytest_extra_args: list[str] = []):
22+
python_version = (sys.version_info.major, sys.version_info.minor, sys.version_info.micro)
23+
vcrpy_is_supported = python_version >= (3, 10, 0)
24+
25+
session.install("-r", "dev-requirements.txt")
26+
if vcrpy_is_supported:
27+
session.install("pytest-vcr")
28+
# install the package for being able to use the entry points we define
29+
session.install("-e", ".")
30+
31+
session.run("pytest", *pytest_extra_args, env={"EDOT_IN_NOX": "1"})
32+
33+
34+
@nox.session
35+
def tests(session):
36+
run_tests(session, pytest_extra_args=session.posargs)

0 commit comments

Comments
 (0)