11from __future__ import annotations
22
3+ import subprocess
34import textwrap
45
56import pytest
@@ -637,12 +638,17 @@ def task_first() -> Annotated[str, Path("out.txt")]:
637638 assert "1 Skipped because unchanged" in result .output
638639
639640
640- def test_task_will_be_executed_after_another_one_with_function (tmp_path ):
641- source = """
641+ @pytest .mark .end_to_end ()
642+ @pytest .mark .parametrize ("decorator" , ["" , "@task" ])
643+ def test_task_will_be_executed_after_another_one_with_function (
644+ runner , tmp_path , decorator
645+ ):
646+ source = f"""
642647 from pytask import task
643648 from pathlib import Path
644649 from typing_extensions import Annotated
645650
651+ { decorator }
646652 def task_first() -> Annotated[str, Path("out.txt")]:
647653 return "Hello, World!"
648654
@@ -652,8 +658,35 @@ def task_second():
652658 """
653659 tmp_path .joinpath ("task_example.py" ).write_text (textwrap .dedent (source ))
654660
655- session = build (paths = tmp_path )
661+ result = runner .invoke (cli , [tmp_path .as_posix ()])
662+ assert result .exit_code == ExitCode .OK
663+
664+
665+ @pytest .mark .end_to_end ()
666+ @pytest .mark .parametrize ("decorator" , ["" , "@task" ])
667+ def test_task_will_be_executed_after_another_one_with_function_session (
668+ tmp_path , decorator
669+ ):
670+ source = f"""
671+ from pytask import task, ExitCode, build
672+ from pathlib import Path
673+ from typing_extensions import Annotated
674+
675+ { decorator }
676+ def task_first() -> Annotated[str, Path("out.txt")]:
677+ return "Hello, World!"
678+
679+ @task(after=task_first)
680+ def task_second():
681+ assert Path(__file__).parent.joinpath("out.txt").exists()
682+
683+ session = build(tasks=[task_first, task_second])
656684 assert session.exit_code == ExitCode.OK
685+ """
686+ tmp_path .joinpath ("task_example.py" ).write_text (textwrap .dedent (source ))
687+
688+ result = subprocess .run (("pytask" ,), cwd = tmp_path , capture_output = True , check = False )
689+ assert result .returncode == ExitCode .OK
657690
658691
659692def test_raise_error_for_wrong_after_expression (runner , tmp_path ):
0 commit comments