You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: allow setting tags on parametrized sessions (#832)
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.
Copy file name to clipboardExpand all lines: docs/config.rst
+57Lines changed: 57 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -397,6 +397,63 @@ Pythons:
397
397
...
398
398
399
399
400
+
Assigning tags to parametrized sessions
401
+
---------------------------------------
402
+
403
+
Just as tags can be :ref:`assigned to normal sessions <session tags>`, they can also be assigned to parametrized sessions. The following examples are both equivalent:
404
+
405
+
.. code-block:: python
406
+
407
+
@nox.session
408
+
@nox.parametrize('dependency',
409
+
['1.0', '2.0'],
410
+
tags=[['old'], ['new']])
411
+
@nox.parametrize('database'
412
+
['postgres', 'mysql'],
413
+
tags=[['psql'], ['mysql']])
414
+
deftests(session, dependency, database):
415
+
...
416
+
417
+
.. code-block:: python
418
+
419
+
@nox.session
420
+
@nox.parametrize('dependency', [
421
+
nox.param('1.0', tags=['old']),
422
+
nox.param('2.0', tags=['new']),
423
+
])
424
+
@nox.parametrize('database', [
425
+
nox.param('postgres', tags=['psql']),
426
+
nox.param('mysql', tags=['mysql']),
427
+
])
428
+
deftests(session, dependency, database):
429
+
...
430
+
431
+
In either case, running ``nox --tags old`` will run the tests using version 1.0 of the dependency against both database backends, while running ``nox --tags psql`` will run the tests using both versions of the dependency, but only against PostgreSQL.
432
+
433
+
More sophisticated tag assignment can be performed by passing a generator to the ``@nox.parametrize`` decorator, as seen in the following example:
434
+
435
+
.. code-block:: python
436
+
437
+
defgenerate_params():
438
+
for dependency in ["1.0", "1.1", "2.0"]:
439
+
for database in ["sqlite", "postgresql", "mysql"]:
440
+
tags = []
441
+
if dependency =="2.0"and database =="sqlite":
442
+
tags.append("quick")
443
+
if dependency =="2.0"or database =="sqlite":
444
+
tags.append("standard")
445
+
yield nox.param((dependency, database), tags)
446
+
447
+
@nox.session
448
+
@nox.parametrize(
449
+
["dependency", "database"], generate_params(),
450
+
)
451
+
deftests(session, dependency, database):
452
+
...
453
+
454
+
In this example, the ``quick`` tag is assigned to the single combination of the latest version of the dependency along with the SQLite database backend, allowing a developer to run the tests in a single configuration as a basic sanity test. The ``standard`` tag, in contrast, selects combinations targeting either the latest version of the dependency *or* the SQLite database backend. If the developer runs ``tox --tags standard``, the tests will be run against all supported versions of the dependency with the SQLite backend, as well as against all supported database backends under the latest version of the dependency, giving much more comprehensive test coverage while using only five of the potential nine test matrix combinations.
0 commit comments