<#5433 [BUG] Task errors are not directly surfaced...
# flyte-github
c
#5433 [BUG] Task errors are not directly surfaced in unit tests in 1.12.0 Issue created by charliemoriarty ### Describe the bug Since upgrading flyte from
1.11.0
->
1.12.0
, unit tests to verify that tasks raise expected errors are no longer passing. Instead of surfacing the error, the tests fail with a SystemExit.
Copy code
from flytekit import task

@task
def f(x: int) -> int:
    if x > 0:
        return x + 2
    else:
        raise ValueError("x must be positive")
    

# Passes in 1.11.0, fails in 1.12.0
def test_f_raises():
    with pytest.raises(ValueError):
        f(-1)
We've been able to bypass this issue by accessing the
task_function
value directly in the tests, but this is non-intuitive and required a lot of manual updates to our test suite:
Copy code
# Passes in 1.12.0
def test_f_raises():
    with pytest.raises(ValueError):
        _f = f.task_function
        _f(-1)
Slack thread: https://flyte-org.slack.com/archives/CP2HDHKE1/p1716391591793619 ### Expected behavior I would expect to be able to test that tasks raise errors directly, without needing to access the internal task function:
Copy code
# Should pass
def test_f_raises():
    with pytest.raises(ValueError):
        f(-1)
### Additional context to reproduce No response ### Screenshots No response ### Are you sure this issue hasn't been raised already? • Yes ### Have you read the Code of Conduct? • Yes flyteorg/flyte