@@ -56,7 +56,7 @@ def task_dummy(depends_on, produces):
5656
5757
5858@pytest .mark .end_to_end
59- def test_skip_if_ancestor_failed (tmp_path ):
59+ def test_skipif_ancestor_failed (tmp_path ):
6060 source = """
6161 import pytask
6262
@@ -102,6 +102,101 @@ def task_second():
102102 assert isinstance (session .execution_reports [1 ].exc_info [1 ], Skipped )
103103
104104
105+ @pytest .mark .end_to_end
106+ def test_if_skipif_decorator_is_applied_skipping (tmp_path ):
107+ source = """
108+ import pytask
109+
110+ @pytask.mark.skipif(condition=True, reason="bla")
111+ @pytask.mark.produces("out.txt")
112+ def task_first():
113+ assert False
114+
115+ @pytask.mark.depends_on("out.txt")
116+ def task_second():
117+ assert False
118+ """
119+ tmp_path .joinpath ("task_dummy.py" ).write_text (textwrap .dedent (source ))
120+
121+ session = main ({"paths" : tmp_path })
122+ node = session .collection_reports [0 ].node
123+ assert len (node .markers ) == 1
124+ assert node .markers [0 ].name == "skipif"
125+ assert node .markers [0 ].args == ()
126+ assert node .markers [0 ].kwargs == {"condition" : True , "reason" : "bla" }
127+
128+ assert session .execution_reports [0 ].success
129+ assert isinstance (session .execution_reports [0 ].exc_info [1 ], Skipped )
130+ assert session .execution_reports [1 ].success
131+ assert isinstance (session .execution_reports [1 ].exc_info [1 ], Skipped )
132+ assert session .execution_reports [0 ].exc_info [1 ].args [0 ] == "bla"
133+
134+
135+ @pytest .mark .end_to_end
136+ def test_if_skipif_decorator_is_applied_execute (tmp_path ):
137+ source = """
138+ import pytask
139+
140+ @pytask.mark.skipif(False, reason="bla")
141+ @pytask.mark.produces("out.txt")
142+ def task_first(produces):
143+ with open(produces, "w") as f:
144+ f.write("hello world.")
145+
146+ @pytask.mark.depends_on("out.txt")
147+ def task_second():
148+ pass
149+ """
150+ tmp_path .joinpath ("task_dummy.py" ).write_text (textwrap .dedent (source ))
151+
152+ session = main ({"paths" : tmp_path })
153+ node = session .collection_reports [0 ].node
154+
155+ assert len (node .markers ) == 1
156+ assert node .markers [0 ].name == "skipif"
157+ assert node .markers [0 ].args == (False ,)
158+ assert node .markers [0 ].kwargs == {"reason" : "bla" }
159+ assert session .execution_reports [0 ].success
160+ assert session .execution_reports [0 ].exc_info is None
161+ assert session .execution_reports [1 ].success
162+ assert session .execution_reports [1 ].exc_info is None
163+
164+
165+ @pytest .mark .end_to_end
166+ def test_if_skipif_decorator_is_applied_any_condition_matches (tmp_path ):
167+ """Any condition of skipif has to be True and only their message is shown."""
168+ source = """
169+ import pytask
170+
171+ @pytask.mark.skipif(condition=False, reason="I am fine")
172+ @pytask.mark.skipif(condition=True, reason="No, I am not.")
173+ @pytask.mark.produces("out.txt")
174+ def task_first():
175+ assert False
176+
177+ @pytask.mark.depends_on("out.txt")
178+ def task_second():
179+ assert False
180+ """
181+ tmp_path .joinpath ("task_dummy.py" ).write_text (textwrap .dedent (source ))
182+
183+ session = main ({"paths" : tmp_path })
184+ node = session .collection_reports [0 ].node
185+ assert len (node .markers ) == 2
186+ assert node .markers [0 ].name == "skipif"
187+ assert node .markers [0 ].args == ()
188+ assert node .markers [0 ].kwargs == {"condition" : True , "reason" : "No, I am not." }
189+ assert node .markers [1 ].name == "skipif"
190+ assert node .markers [1 ].args == ()
191+ assert node .markers [1 ].kwargs == {"condition" : False , "reason" : "I am fine" }
192+
193+ assert session .execution_reports [0 ].success
194+ assert isinstance (session .execution_reports [0 ].exc_info [1 ], Skipped )
195+ assert session .execution_reports [1 ].success
196+ assert isinstance (session .execution_reports [1 ].exc_info [1 ], Skipped )
197+ assert session .execution_reports [0 ].exc_info [1 ].args [0 ] == "No, I am not."
198+
199+
105200@pytest .mark .unit
106201@pytest .mark .parametrize (
107202 ("marker_name" , "expectation" ),
0 commit comments