diff --git a/ixmp/tests/test_tutorials.py b/ixmp/tests/test_tutorials.py index dc7cee6fb..6d82dc395 100644 --- a/ixmp/tests/test_tutorials.py +++ b/ixmp/tests/test_tutorials.py @@ -15,26 +15,23 @@ FLAKY = pytest.mark.flaky( reruns=5, rerun_delay=2, - condition="GITHUB_ACTIONS" in os.environ and platform.system() == "Windows", + condition=GHA and platform.system() == "Windows", reason="Flaky; see iiasa/ixmp#543", ) +@pytest.fixture(scope="session") def default_args(): """Default arguments for :func:`.run_notebook.""" - if GHA: - # Use a longer timeout - return dict(timeout=30) - else: - return dict() + # Use a longer timeout for GHA + return dict(timeout=30) if GHA else dict() @FLAKY @pytest.mark.xdist_group(name=f"{group_base_name}-0") -def test_py_transport(tutorial_path, tmp_path, tmp_env): +def test_py_transport(tutorial_path, tmp_path, tmp_env, default_args): fname = tutorial_path / "transport" / "py_transport.ipynb" - args = default_args() - nb, errors = run_notebook(fname, tmp_path, tmp_env, **args) + nb, errors = run_notebook(fname, tmp_path, tmp_env, **default_args) assert errors == [] # FIXME use get_cell_by_name instead of assuming cell count/order is fixed @@ -42,10 +39,9 @@ def test_py_transport(tutorial_path, tmp_path, tmp_env): @pytest.mark.xdist_group(name=f"{group_base_name}-0") -def test_py_transport_scenario(tutorial_path, tmp_path, tmp_env): +def test_py_transport_scenario(tutorial_path, tmp_path, tmp_env, default_args): fname = tutorial_path / "transport" / "py_transport_scenario.ipynb" - args = default_args() - nb, errors = run_notebook(fname, tmp_path, tmp_env, **args) + nb, errors = run_notebook(fname, tmp_path, tmp_env, **default_args) assert errors == [] assert np.isclose(get_cell_output(nb, "scen-z")["lvl"], 153.675) @@ -56,24 +52,22 @@ def test_py_transport_scenario(tutorial_path, tmp_path, tmp_env): @pytest.mark.xdist_group(name=f"{group_base_name}-1") @pytest.mark.rixmp # TODO investigate and resolve the cause of the time outs; remove this mark -@pytest.mark.skipif( - "GITHUB_ACTIONS" in os.environ and sys.platform == "linux", reason="Times out" -) -def test_R_transport(tutorial_path, tmp_path, tmp_env): +@pytest.mark.skipif(GHA and sys.platform == "linux", reason="Times out") +def test_R_transport(tutorial_path, tmp_path, tmp_env, default_args): fname = tutorial_path / "transport" / "R_transport.ipynb" - args = default_args() - nb, errors = run_notebook(fname, tmp_path, tmp_env, kernel_name="IR", **args) + nb, errors = run_notebook( + fname, tmp_path, tmp_env, kernel_name="IR", **default_args + ) assert errors == [] @pytest.mark.xdist_group(name=f"{group_base_name}-1") @pytest.mark.rixmp # TODO investigate and resolve the cause of the time outs; remove this mark -@pytest.mark.skipif( - "GITHUB_ACTIONS" in os.environ and sys.platform == "linux", reason="Times out" -) -def test_R_transport_scenario(tutorial_path, tmp_path, tmp_env): +@pytest.mark.skipif(GHA and sys.platform == "linux", reason="Times out") +def test_R_transport_scenario(tutorial_path, tmp_path, tmp_env, default_args): fname = tutorial_path / "transport" / "R_transport_scenario.ipynb" - args = default_args() - nb, errors = run_notebook(fname, tmp_path, tmp_env, kernel_name="IR", **args) + nb, errors = run_notebook( + fname, tmp_path, tmp_env, kernel_name="IR", **default_args + ) assert errors == []