-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #474 from MongoEngine/test-matrix-nox
CI/CD Test matrix extended to test all mongo db versions and re-check minimum supported requirements
- Loading branch information
Showing
9 changed files
with
142 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ venv/ | |
.project | ||
.pydevproject | ||
.tox | ||
.nox | ||
.eggs | ||
.idea | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ pre-commit | |
pytest | ||
pytest-cov | ||
pytest-mock | ||
tox | ||
nox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters