Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow setting tags on parametrized sessions #832

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

living180
Copy link
Contributor

@living180 living180 commented May 29, 2024

To allow more fine-grained session selection, allow tags to be set on individual parametrized sessions via either a tags argument to the @nox.parametrize() decorator, or a tags argument to nox.param() (similar to how parametrized session IDs can be specified). Any tags specified this way will be added to any tags passed to the @nox.session() decorator.

A couple of examples of how this could be used:

@nox.session
@nox.parametrize(
    "db_engine", [
        nox.param("sqlite", tags=["sqlite"])
        nox.param("mysql", tags=["mysql"])
        nox.param("postgresql", tags=["psql"])
    ]
)
@nox.parametrize(
    "django", [
        nox.param(">=3,<4", tags=["django3"])
        nox.param(">=4,<5", tags=["django4"])
        nox.param(">=5,<6", tags=["django5"])
    ]
)
def test(session, db_engine, django):
    pass

In this case, a developer could run nox -t sqlite to run just the tests with all versions of Django but only using the SQLite backend.

Here's a more complex example:

def generate_params():
    for python in ["3.10", "3.11", 3.12"]:
        for django in [3, 4, 5]:
            tags = []
            if python == "3.12" and django == 5:
                tags.append("quick")
            if python == "3.12" or django == 5:
                tags.append("standard")
            yield nox.param([python, django], tags)

@nox.session
@nox.parametrize(
    ["python", "django"], generate_params(),
)
def test(session, django):
    pass

This tags the Python 3.12/Django 5 combination with the quick tag, allowing the developer to run a quick sanity check on the code using a single entry from the test matrix. It also tags any combination of Python 3.12 or Django 5 with the standard tag, allowing the developer to run the tests using Python 3.12 with all versions of Django along with all versions of Python with Django 5, which should give fairly comprehensive test coverage while only having to run five entries from the test matrix instead of nine.

@living180
Copy link
Contributor Author

If this feature/approach is acceptable, I will update the PR to add the necessary documentation updates as well.

@living180 living180 marked this pull request as draft May 29, 2024 08:01
@living180 living180 marked this pull request as ready for review May 29, 2024 08:01
@henryiii
Copy link
Collaborator

Seems reasonable.

To allow more fine-grained session selection, allow tags to be set on
individual parametrized sessions via either a tags argument to the
@nox.parametrize() decorator, or a tags argument to nox.param() (similar
to how parametrized session IDs can be specified).  Any tags specified
this way will be added to any tags passed to the @nox.session()
decorator.
@henryiii henryiii merged commit f2be46a into wntrblm:main Oct 1, 2024
23 checks passed
@living180 living180 deleted the parametrized_tags branch October 1, 2024 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants