Switch from tox to nox

Recent tox releases have put us on a config treadmill. Avoid these
issues entirely by using nox. Nox is a tox alternative that uses
standard tools like pip and should be simpler to use for us.

Change-Id: Ie79845bbed7ca1254aec466bd5219186fefcdac9
This commit is contained in:
Clark Boylan 2023-01-24 10:13:35 -08:00
parent f02b41df74
commit 12a0aca425
7 changed files with 83 additions and 62 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@ ChangeLog
.gerrit .gerrit
.testrepository .testrepository
.tox .tox
.nox
.venv .venv
*.egg *.egg
*.egg-info *.egg-info

View File

@ -2,18 +2,18 @@
vars: vars:
release_python: python3 release_python: python3
templates: templates:
- publish-opendev-tox-docs - publish-opendev-nox-docs
check: check:
jobs: &jobs jobs: &jobs
- build-python-release - build-python-release
- tox-linters - nox-linters
- tox-py36: - nox-py36:
nodeset: ubuntu-bionic nodeset: ubuntu-bionic
- tox-py37: - nox-py37:
nodeset: ubuntu-bionic nodeset: ubuntu-bionic
- tox-py38: - nox-py38:
nodeset: ubuntu-focal nodeset: ubuntu-focal
- tox-py39: - nox-py39:
nodeset: ubuntu-focal nodeset: ubuntu-focal
gate: gate:
jobs: *jobs jobs: *jobs
@ -23,4 +23,4 @@
release: release:
jobs: jobs:
- opendev-release-python - opendev-release-python
- opendev-publish-unversioned-tox-docs - opendev-publish-unversioned-nox-docs

View File

@ -20,13 +20,13 @@ tools, or review ``bindep.txt`` by hand.
Running Tests Running Tests
------------- -------------
The testing system is based on a combination of tox and testr. The canonical The testing system is based on a combination of nox and testr. The canonical
approach to running tests is to simply run the command `tox`. This will approach to running tests is to simply run the command `nox`. This will
create virtual environments, populate them with dependencies and run all of create virtual environments, populate them with dependencies and run all of
the tests that OpenStack CI systems run. Behind the scenes, tox is running the tests that OpenStack CI systems run. Behind the scenes, nox is running
`testr run --parallel`, but is set up such that you can supply any additional `stestr run`, but is set up such that you can supply any additional
testr arguments that are needed to tox. For example, you can run: stestr arguments that are needed to nox. For example, you can run:
`tox -- --analyze-isolation` to cause tox to tell testr to add `nox -s tests -- --analyze-isolation` to cause nox to tell testr to add
--analyze-isolation to its argument list. --analyze-isolation to its argument list.
It is also possible to run the tests inside of a virtual environment It is also possible to run the tests inside of a virtual environment
@ -38,7 +38,6 @@ test-requirements.txt. Installing them via pip, for instance, is simply::
pip install -r requirements.txt -r test-requirements.txt pip install -r requirements.txt -r test-requirements.txt
In you go this route, you can interact with the testr command directly. In you go this route, you can interact with the testr command directly.
Running `testr run` will run the entire test suite. `testr run --parallel` Running `stestr run` will run the entire test suite.
will run it in parallel (this is the default incantation tox uses.) More More information about testr can be found at:
information about testr can be found at: https://stestr.readthedocs.io/en/latest/README.html
https://testrepository.readthedocs.io/en/latest/

View File

@ -13,7 +13,7 @@ following:
cached copy (it needs to be located in a ``.gerrit`` directory at the cached copy (it needs to be located in a ``.gerrit`` directory at the
top level of the git-review project) top level of the git-review project)
To run git-review integration tests, use tox. For example, to test against To run git-review integration tests, use nox. For example, to test against
Python 3.7:: Python 3::
tox -e py37 nox -s tests

58
noxfile.py Normal file
View File

@ -0,0 +1,58 @@
# Licensed 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
nox.options.error_on_external_run = True
nox.options.reuse_existing_virtualenvs = True
nox.options.sessions = ["tests-3", "docs", "linters"]
@nox.session(python="3")
def linters(session):
session.install("-r", "requirements.txt")
session.install("-r", "test-requirements.txt")
session.install("-e", ".")
session.run("flake8")
@nox.session(python="3")
def docs(session):
session.install("-r", "requirements.txt")
session.install("-r", "doc/requirements.txt")
session.install("-e", ".")
session.run(
"sphinx-build", "-W",
"-d", "doc/build/doctrees",
"-b", "html",
"doc/source/", "doc/build/html"
)
@nox.session(python="3")
def venv(session):
session.install("-r", "requirements.txt")
session.install("-r", "test-requirements.txt")
session.install("-e", ".")
session.run(*session.posargs)
@nox.session(python="3")
def tests(session):
session.install("-r", "requirements.txt")
session.install("-r", "test-requirements.txt")
session.install("-e", ".")
session.run("python", "-m", "git_review.tests.check_test_id_hashes",
"discover", "--list")
session.run("python", "-m", "git_review.tests.prepare")
session.run("stestr", "run", "--color", *session.posargs)

View File

@ -42,3 +42,8 @@ console_scripts =
[pbr] [pbr]
manpages = manpages =
git-review.1 git-review.1
[flake8]
ignore = E125,H202,H405,H904,W504
show-source = true
exclude = .venv,.git,.tox,.nox,dist,doc,releasenotes,*lib/python*,*egg,build

42
tox.ini
View File

@ -1,42 +0,0 @@
[tox]
envlist = linters,docs,py3
ignore_basepython_conflict = true
[testenv]
basepython = python3
usedevelop = true
# See "testing behind a proxy" https://review.opendev.org/624496
passenv =
http_proxy
https_proxy
# avoids potential slip-over of java 1.9 which breaks Gerrit, without it
# Gerrit may start with incompatible java version.
JAVA_HOME
# uncomment to allow custom java options to be added
# _JAVA_OPTIONS
TERM
commands =
python -m git_review.tests.check_test_id_hashes discover --list
python -m git_review.tests.prepare
stestr run --color {posargs}
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
[testenv:linters]
commands = flake8
[testenv:docs]
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/doc/requirements.txt
commands =
sphinx-build -W -d doc/build/doctrees -b html doc/source/ doc/build/html
[testenv:venv]
commands = {posargs}
[flake8]
ignore = E125,H202,H405,H904,W504
show-source = true
exclude = .venv,.git,.tox,dist,doc,releasenotes,*lib/python*,*egg,build