Skip to content

Commit

Permalink
fixing the test so it works for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
djarecka committed Feb 25, 2021
1 parent b5cce71 commit fe99b90
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pydra/engine/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ def myhook_postrun(task, result, *args):
assert "postrun task hook was called" in hook_messages[0]


def test_traceback():
def test_traceback(tmpdir):
""" checking if the error raised in a function is properly returned;
checking if there is an error filename in the error message that contains
full traceback including the line in the python function
Expand All @@ -1317,23 +1317,24 @@ def test_traceback():
def fun_error(x):
raise Exception("Error from the function")

task = fun_error(name="error", x=[3, 4]).split("x")
task = fun_error(name="error", x=[3, 4], cache_dir=tmpdir).split("x")

with pytest.raises(Exception, match="from the function") as exinfo:
res = task()

# getting error file from the error message
error_file_match = re.findall("[a-zA-Z0-9/_]+error.pklz", str(exinfo.value))
assert len(error_file_match) # should be one error file in the error message
error_file = Path(error_file_match[0])
assert error_file.name == "_error.pklz"
error_file_match = str(exinfo.value).split("here: ")[-1].split("_error.pklz")[0]
error_file = Path(error_file_match) / "_error.pklz"
# checking if the file exists
assert error_file.exists()
# reading error message from the pickle file
error_tb = cp.loads(error_file.read_bytes())["error message"]
# the error traceback should be a list and should point to a specific line in the function
assert isinstance(error_tb, list)
assert "in fun_error" in error_tb[-2]


def test_traceback_wf():
def test_traceback_wf(tmpdir):
""" checking if the error raised in a function is properly returned by a workflow;
checking if there is an error filename in the error message that contains
full traceback including the line in the python function
Expand All @@ -1343,18 +1344,19 @@ def test_traceback_wf():
def fun_error(x):
raise Exception("Error from the function")

wf = Workflow(name="wf", input_spec=["x"], x=[3, 4]).split("x")
wf = Workflow(name="wf", input_spec=["x"], x=[3, 4], cache_dir=tmpdir).split("x")
wf.add(fun_error(name="error", x=wf.lzin.x))
wf.set_output([("out", wf.error.lzout.out)])

with pytest.raises(Exception, match="Task error raised an error") as exinfo:
res = wf()

# getting error file from the error message
error_file_match = re.findall("[a-zA-Z0-9/_]+error.pklz", str(exinfo.value))
assert len(error_file_match) # should be one error file in the error message
error_file = Path(error_file_match[0])
assert error_file.name == "_error.pklz"
error_file_match = str(exinfo.value).split("here: ")[-1].split("_error.pklz")[0]
error_file = Path(error_file_match) / "_error.pklz"
# checking if the file exists
assert error_file.exists()
# reading error message from the pickle file
error_tb = cp.loads(error_file.read_bytes())["error message"]
# the error traceback should be a list and should point to a specific line in the function
assert isinstance(error_tb, list)
Expand Down

0 comments on commit fe99b90

Please sign in to comment.