Skip to content

Commit 34573d4

Browse files
committed
merged.
1 parent 9beeb33 commit 34573d4

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ all releases are available on `Anaconda.org
1111
------------------
1212

1313
- :gh:`5` fixes the CI and other smaller issues.
14+
- :gh:`8` aligns pytask-parallel with task priorities in pytask v0.0.11.
1415
- :gh:`9` enables --max-failures. Closes :gh:`7`.
1516

1617

src/pytask_parallel/execute.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ def pytask_execute_build(session):
118118

119119

120120
class ProcessesNameSpace:
121+
"""The name space for hooks related to processes."""
122+
121123
@hookimpl(tryfirst=True)
122124
def pytask_execute_task(session, task): # noqa: N805
123125
"""Execute a task.
@@ -142,6 +144,8 @@ def unserialize_and_execute_task(bytes_):
142144

143145

144146
class DefaultBackendNameSpace:
147+
"""The name space for hooks related to threads."""
148+
145149
@hookimpl(tryfirst=True)
146150
def pytask_execute_task(session, task): # noqa: N805
147151
"""Execute a task.

tests/test_execute.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import textwrap
33
from time import time
44

5+
import attr
56
import pytest
67
from pytask import cli
78
from pytask import main
@@ -10,9 +11,9 @@
1011
from pytask_parallel.execute import ProcessesNameSpace
1112

1213

14+
@attr.s
1315
class DummyTask:
14-
def __init__(self, function):
15-
self.function = function
16+
function = attr.ib()
1617

1718
def execute(self):
1819
self.function()
@@ -188,3 +189,38 @@ def task_1(): pass
188189

189190
assert len(session.tasks) == 3
190191
assert len(session.execution_reports) == 2
192+
193+
194+
@pytest.mark.end_to_end
195+
@pytest.mark.parametrize("parallel_backend", PARALLEL_BACKENDS)
196+
def test_task_priorities(tmp_path, parallel_backend):
197+
source = """
198+
import pytask
199+
import time
200+
201+
@pytask.mark.try_first
202+
def task_0():
203+
time.sleep(1)
204+
205+
def task_1():
206+
time.sleep(1)
207+
208+
@pytask.mark.try_last
209+
def task_2():
210+
time.sleep(1)
211+
212+
def task_3():
213+
time.sleep(1)
214+
215+
def task_4():
216+
time.sleep(1)
217+
"""
218+
tmp_path.joinpath("task_dummy.py").write_text(textwrap.dedent(source))
219+
220+
session = main(
221+
{"paths": tmp_path, "parallel_backend": parallel_backend, "n_workers": 2}
222+
)
223+
224+
assert session.exit_code == 0
225+
assert session.execution_reports[0].task.name.endswith("task_0")
226+
assert session.execution_reports[-1].task.name.endswith("task_2")

0 commit comments

Comments
 (0)