Skip to content

Commit

Permalink
Use nox for test automation
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya committed May 9, 2022
1 parent 012b2a6 commit 3c121e5
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 38 deletions.
20 changes: 7 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
strategy:
matrix:
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
Expand All @@ -34,9 +35,8 @@ jobs:
architecture: x64

- run: |
python -m venv venv
venv/bin/pip install -r requirements_test.txt
venv/bin/py.test tests/
pip install nox==2022.1.7 poetry==1.1.13
nox -rs tests
coverage:

Expand All @@ -53,16 +53,10 @@ jobs:
architecture: x64

- run: |
python -m venv venv
venv/bin/pip install -r requirements_test.txt
venv/bin/py.test \
-s \
--verbose \
--cov-report term-missing \
--cov-report xml \
--cov=aioridwell tests
- uses: codecov/codecov-action@v3
pip install nox==2022.1.7 poetry==1.1.13
nox -rs coverage
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}

Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
.DS_Store
.coverage
.mypy_cache
.tox/
.nox
.tox
.venv
__pycache__/
__pycache__
coverage.xml
dist
docs/_build
poetry.lock
tags
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ asyncio.run(main())
5. Install the dev environment: `script/setup`
6. Code your new feature or bug fix.
7. Write tests that cover your new functionality.
8. Run tests and ensure 100% code coverage: `script/test`
8. Run tests and ensure 100% code coverage: `nox -rs coverage`
9. Update `README.md` with any new documentation.
10. Add yourself to `AUTHORS.md`.
11. Submit a pull request!
48 changes: 48 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Define nox actions."""
import tempfile
from typing import Any

import nox


def install_with_constraints(session: nox.sessions.Session, *args: str, **kwargs: Any):
"""Install PyPI packages based on pyproject.toml constraints."""
with tempfile.NamedTemporaryFile() as requirements:
session.run(
"poetry",
"export",
"--dev",
"--without-hashes",
"--format=requirements.txt",
f"--output={requirements.name}",
external=True,
)
session.install(f"--constraint={requirements.name}", *args, **kwargs)


@nox.session
def coverage(session: nox.sessions.Session) -> None:
"""Run all tests."""
args = session.posargs or [
"-s",
"--cov=aioridwell",
"--cov-report=term-missing",
"--cov-report=xml",
"tests/",
]
session.run("poetry", "install", "--no-dev", external=True)
install_with_constraints(
session, "aresponses", "freezegun", "pytest", "pytest-aiohttp", "pytest-cov"
)
session.run("pytest", *args)


@nox.session
def tests(session: nox.sessions.Session) -> None:
"""Run all tests."""
args = session.posargs or ["-s", "tests/"]
session.run("poetry", "install", "--no-dev", external=True)
install_with_constraints(
session, "aresponses", "freezegun", "pytest", "pytest-aiohttp"
)
session.run("pytest", *args)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ titlecase = "^2.3"
[tool.poetry.dev-dependencies]
aresponses = "^2.0.0"
freezegun = "^1.1.0"
nox = "^2022.1.7"
pre-commit = "^2.0.1"
pytest = "^7.0.0"
pytest-aiohttp = "^1.0.0"
Expand Down
10 changes: 0 additions & 10 deletions requirements_test.txt

This file was deleted.

6 changes: 0 additions & 6 deletions script/docs

This file was deleted.

5 changes: 0 additions & 5 deletions script/test

This file was deleted.

0 comments on commit 3c121e5

Please sign in to comment.