1
1
from __future__ import annotations
2
2
3
+ import subprocess
3
4
import textwrap
4
5
5
6
import pytest
@@ -637,12 +638,17 @@ def task_first() -> Annotated[str, Path("out.txt")]:
637
638
assert "1 Skipped because unchanged" in result .output
638
639
639
640
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"""
642
647
from pytask import task
643
648
from pathlib import Path
644
649
from typing_extensions import Annotated
645
650
651
+ { decorator }
646
652
def task_first() -> Annotated[str, Path("out.txt")]:
647
653
return "Hello, World!"
648
654
@@ -652,8 +658,35 @@ def task_second():
652
658
"""
653
659
tmp_path .joinpath ("task_example.py" ).write_text (textwrap .dedent (source ))
654
660
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])
656
684
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
657
690
658
691
659
692
def test_raise_error_for_wrong_after_expression (runner , tmp_path ):
0 commit comments