Add a testing tool chain
- use pytest as the base, measure coverage with pytest-cov
+ configure coverage to include branches and specify source locations
+ configure pytest to enforce explicit markers
- add a package for the test suite under tests/
- add a `__version__` identifier at the package's root
+ it is dynamically assigned the version of the installed package
+ the version is PEP440 compliant and follows a strict subset of
semantic versioning: x.y.z[.devN] where x, y, z, and N are all
non-negative integers
+ add module with tests for the __version__
- add a nox session "test" that runs the test suite
- use flake8 to lint pytest for consistent style
This commit is contained in:
parent
c7989e0040
commit
9fc5b4816a
7 changed files with 406 additions and 3 deletions
26
noxfile.py
26
noxfile.py
|
|
@ -14,8 +14,11 @@ MAIN_PYTHON = '3.8'
|
|||
# Keep the project is forward compatible.
|
||||
NEXT_PYTHON = '3.9'
|
||||
|
||||
# Path to the test suite.
|
||||
PYTEST_LOCATION = 'tests/'
|
||||
|
||||
# Paths with *.py files.
|
||||
SRC_LOCATIONS = 'noxfile.py', 'src/'
|
||||
SRC_LOCATIONS = 'noxfile.py', 'src/', PYTEST_LOCATION
|
||||
|
||||
|
||||
# Use a unified .cache/ folder for all tools.
|
||||
|
|
@ -70,6 +73,7 @@ def lint(session: Session) -> None:
|
|||
'flake8-annotations',
|
||||
'flake8-black',
|
||||
'flake8-expression-complexity',
|
||||
'flake8-pytest-style',
|
||||
'mypy',
|
||||
'pylint',
|
||||
'wemake-python-styleguide',
|
||||
|
|
@ -96,7 +100,27 @@ def lint(session: Session) -> None:
|
|||
@nox.session(python=[MAIN_PYTHON, NEXT_PYTHON])
|
||||
def test(session: Session) -> None:
|
||||
"""Test the code base."""
|
||||
# Re-using an old environment is not so easy here as
|
||||
# `poetry install --no-dev` removes previously installed packages.
|
||||
# We keep things simple and forbid such usage.
|
||||
if session.virtualenv.reuse_existing:
|
||||
raise RuntimeError('The "test" session must be run with the "-r" option')
|
||||
|
||||
_begin(session)
|
||||
# Install only the non-develop dependencies
|
||||
# and the testing tool chain.
|
||||
session.run('poetry', 'install', '--no-dev', external=True)
|
||||
_install_packages(session, 'pytest', 'pytest-cov')
|
||||
# Interpret extra arguments as options for pytest.
|
||||
args = session.posargs or (
|
||||
'--cov',
|
||||
'--no-cov-on-fail',
|
||||
'--cov-branch',
|
||||
'--cov-fail-under=100',
|
||||
'--cov-report=term-missing:skip-covered',
|
||||
PYTEST_LOCATION,
|
||||
)
|
||||
session.run('pytest', *args)
|
||||
|
||||
|
||||
@nox.session(name='pre-commit', python=MAIN_PYTHON, venv_backend='none')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue