Skip to content

Commit

Permalink
tests: add test for modern parametrize
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Oct 26, 2024
1 parent 661674a commit 08cc132
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
35 changes: 35 additions & 0 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,41 @@ You can also pass the notified session positional arguments:
Note that this will only have the desired effect if selecting sessions to run via the ``--session/-s`` flag. If you simply run ``nox``, all selected sessions will be run.

Requiring sessions
------------------

You can also request sessions be run before your session runs. This is done with the ``needs=`` keyword:


.. code-block:: python
@nox.session
def tests(session):
session.install("pytest")
session.run("pytest")
@nox.session(needs=["tests"])
def coverage(session):
session.install("coverage")
session.run("coverage")
The required sessions will be stably topologically sorted and run. Parametrized
sessions are supported. You can also get the current Python version with
``{python}``, though arbitrary parametrizations are not supported.


.. code-block:: python
@nox.session(python=["3.10", "3.13"])
def tests(session):
session.install("pytest")
session.run("pytest")
@nox.session(python=["3.10", "3.13"], needs=["tests-{python}"])
def coverage(session):
session.install("coverage")
session.run("coverage")
Testing against different and multiple Pythons
----------------------------------------------

Expand Down
3 changes: 1 addition & 2 deletions nox/_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ def extend_walk(
walk_list = list(walk)
cycle = walk_list[walk_list.index(node) :] + [node]
raise CycleError("Nodes are in a dependency cycle", tuple(cycle))
else:
walk[node] = None
walk[node] = None
return walk

sort = prepended_by_dependencies(root)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ def test_main_with_bad_session_names(run_nox, session):
(("g", "a", "d"), ("b", "c", "h", "g", "a", "e", "d")),
(("m",), ("k-3.9", "k-3.10", "m")),
(("n",), ("k-3.10", "n")),
(("v",), ("u(django='1.9')", "u(django='2.0')", "v")),
(("w",), ("u(django='1.9')", "u(django='2.0')", "w")),
],
)
def test_main_requires(run_nox, sessions, expected_order):
Expand Down Expand Up @@ -539,6 +541,13 @@ def test_main_requires_chain_fail(run_nox, session):
assert "Prerequisite session r was not successful" in stderr


@pytest.mark.parametrize("session", ("w", "u"))
def test_main_requries_modern_param(run_nox, session):
noxfile = os.path.join(RESOURCES, "noxfile_requires.py")
returncode, _, stderr = run_nox(f"--noxfile={noxfile}", f"--session={session}")
assert returncode == 0


def test_main_noxfile_options(monkeypatch, generate_noxfile_options):
noxfile_path = generate_noxfile_options(reuse_existing_virtualenvs=True)
monkeypatch.setattr(
Expand Down

0 comments on commit 08cc132

Please sign in to comment.