Skip to content

Commit

Permalink
Merge pull request #474 from MongoEngine/test-matrix-nox
Browse files Browse the repository at this point in the history
CI/CD Test matrix extended to test all mongo db versions and re-check minimum supported requirements
  • Loading branch information
insspb committed Jul 7, 2022
2 parents 12f837a + f66a6db commit 8647a85
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 50 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@ jobs:
strategy:
fail-fast: false
matrix:
mongodb-version: [4.2]
mongodb-version: [5.0]
include:
- name: "coverage"
python: "3.8"
tox_env: "py38"
python: "3.10"

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox virtualenv
pip install nox virtualenv
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.7.0
with:
mongodb-version: ${{ matrix.mongodb-version }}
- name: Test build
run: "tox -e ${{ matrix.tox_env }} -- --cov-report=xml --cov-report=html"
run: "nox -s latest --python ${{ matrix.python }} -- --cov-report=xml --cov-report=html"
- name: Send coverage report to codecov
uses: codecov/codecov-action@v3
with:
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Linting Tests
# Only for last versions of python
# Only for least supported python version

on:
push:
Expand All @@ -20,17 +20,16 @@ jobs:
include:
- name: "linting"
python: "3.7"
tox_env: "lint"

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox virtualenv
pip install nox virtualenv
- name: Test build
run: "tox -e ${{ matrix.tox_env }}"
run: "nox -s lint"
23 changes: 4 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,8 @@ jobs:
strategy:
fail-fast: false
matrix:
mongodb-version: [3.6, 4.0, 4.2, 4.4]
include:
- name: "ubuntu-py37"
python: "3.7"
tox_env: "py37"
- name: "ubuntu-py38"
python: "3.8"
tox_env: "py38"
- name: "ubuntu-py39"
python: "3.9"
tox_env: "py39"
- name: "ubuntu-py310"
python: "3.10"
tox_env: "py310"
- name: "ubuntu-pypy3"
python: "pypy3.7"
tox_env: "pypy3"
mongodb-version: ["3.6", "4.0", "4.2", "4.4", "5.0"]
python: ["3.7", "3.8", "3.9", "3.10", "pypy3.7"]

steps:
- uses: actions/checkout@v3
Expand All @@ -43,10 +28,10 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox virtualenv
pip install nox virtualenv
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.7.0
with:
mongodb-version: ${{ matrix.mongodb-version }}
- name: Test build
run: "tox -e ${{ matrix.tox_env }}"
run: "nox -s ci_cd_tests --python ${{ matrix.python }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ venv/
.project
.pydevproject
.tox
.nox
.eggs
.idea
.vscode
Expand Down
125 changes: 125 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"""Nox tool configuration file.
Nox is Tox tool replacement.
"""
import shutil
from pathlib import Path

import nox

nox.options.sessions = "latest", "lint", "documentation_tests"
db_version = "5.0"


def base_install(session, flask, mongoengine):
"""Create basic environment setup for tests and linting."""
session.install("-r", "requirements-dev.txt")
if flask == "==1.1.4":
session.install(
f"Flask{flask}",
f"mongoengine{mongoengine}",
"MarkupSafe==2.0.1",
"-e",
".",
)
else:
session.install(
f"Flask{flask}",
f"mongoengine{mongoengine}",
"-e",
".",
)
return session


@nox.session(python="3.7")
def lint(session):
"""Run linting check locally."""
session.install("pre-commit")
session.run("pre-commit", "run", "-a")


@nox.session(python=["3.7", "3.8", "3.9", "3.10", "pypy3.7"])
@nox.parametrize("flask", ["==1.1.4", "==2.0.3", ">=2.1.2"])
@nox.parametrize("mongoengine", ["==0.21.0", "==0.22.1", "==0.23.1", ">=0.24.1"])
def ci_cd_tests(session, flask, mongoengine):
"""Run test suite with pytest into ci_cd (no docker)."""
session = base_install(session, flask, mongoengine)
session.run("pytest", *session.posargs)


def _run_in_docker(session):
session.run(
"docker",
"run",
"--name",
"nox_docker_test",
"-p",
"27017:27017",
"-d",
f"mongo:{db_version}",
external=True,
)
try:
session.run("pytest", *session.posargs)
finally:
session.run_always("docker", "rm", "-fv", "nox_docker_test", external=True)


@nox.session(python=["3.7", "3.8", "3.9", "3.10", "pypy3.7"])
@nox.parametrize("flask", ["==1.1.4", "==2.0.3", ">=2.1.2"])
@nox.parametrize("mongoengine", ["==0.21.0", "==0.22.1", "==0.23.1", ">=0.24.1"])
def full_tests(session, flask, mongoengine):
"""Run tests locally with docker and complete support matrix."""
session = base_install(session, flask, mongoengine)
_run_in_docker(session)


@nox.session(python=["3.7", "3.8", "3.9", "3.10", "pypy3.7"])
def latest(session):
"""Run minimum tests for checking minimum code quality."""
flask = ">=2.1.2"
mongoengine = ">=0.24.1"
session = base_install(session, flask, mongoengine)
if session.interactive:
_run_in_docker(session)
else:
session.run("pytest", *session.posargs)


@nox.session(python="3.10")
def documentation_tests(session):
"""Run documentation tests."""
return docs(session, batch_run=True)


@nox.session(python="3.10")
def docs(session, batch_run: bool = False):
"""Build the documentation or serve documentation interactively."""
shutil.rmtree(Path("docs").joinpath("_build"), ignore_errors=True)
session.install("-r", "docs/requirements.txt")
session.install("-e", ".")
session.cd("docs")
sphinx_args = ["-b", "html", "-W", ".", "_build/html"]

if not session.interactive or batch_run:
sphinx_cmd = "sphinx-build"
else:
sphinx_cmd = "sphinx-autobuild"
sphinx_args.extend(
[
"--open-browser",
"--port",
"9812",
"--watch",
"../*.md",
"--watch",
"../*.rst",
"--watch",
"../*.py",
"--watch",
"../flask_mongoengine",
]
)

session.run(sphinx_cmd, *sphinx_args)
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pre-commit
pytest
pytest-cov
pytest-mock
tox
nox
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ testpaths = tests
[flake8]
ignore=E501,F403,F405,I201,W503,E203
max-line-length=90
exclude=build,dist,docs,examples,venv,.tox,.eggs
exclude=build,dist,docs,examples,venv,.tox,.eggs,.nox
max-complexity=17

[report]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_version(version_tuple):
platforms="any",
python_requires=">=3.7",
install_requires=[
"Flask>=1.1.2",
"Flask>=1.1.4",
"WTForms[email]>=2.3.1",
"Flask-WTF>=0.14.3",
"mongoengine>=0.21",
Expand Down
17 changes: 0 additions & 17 deletions tox.ini

This file was deleted.

0 comments on commit 8647a85

Please sign in to comment.