Using default tool values for reusable noxfile

172 Views Asked by At

I am implementing a reusable noxfile, my goal is that the different Python components of my project can have the same workflow for testing, linting, etc.

To do this, I created a nox_plugin module containing this generic noxfile.py (this is a sample):

import nox

@nox.session(reuse_venv=True)
def tests(session: nox.Session) -> None:
    """
    Run unit tests with required coverage.
    """
    session.install("-r", "dev-requirements.txt")
    session.run("coverage", "run", "-m", "pytest", "src")
    session.run("coverage", "json")
    session.run("coverage", "report")
    session.run("coverage-threshold")

I can package this module into a wheel that I can reuse by simply using the following noxfile.py in other projects:

from nox_plugin import tests

and executing the nox command.

However, I have to redefine the pyproject.toml sections for the coverage and coverage-threshold tools in all the modules using the nox_plugin package:

# Coverage configuration
[tool.coverage.run]
branch = true
omit = ["*__init__.py"]
include = ["src/main/*"]

[tool.coverage.report]
precision = 2

# Coverage-threshold configuration
[tool.coverage-threshold]
line_coverage_min = 90
file_line_coverage_min = 90
branch_coverage_min = 80
file_branch_coverage_min = 80

I would like to define default values for those sections in my nox_plugin module. This way, I can have a default configuration followed by all repos (for example, the same linting threshold for all code, or the same coverage thresholds).

0

There are 0 best solutions below