how does everyone test the results of a task? ``` ...
# ask-community
c
how does everyone test the results of a task?
Copy code
with Flow("test_target_transformer") as f:
        te = fit_target_transformer(problem, target, train_data)
        df = target_encoder_transform(te, imputed_categorical_df)
 assert df.isna().sum() == 0
I'm trying to test a @task that returns a dataframe, but assert statement errors on
AttributeError: 'FunctionTask' object has no attribute 'isna'
. How do I return this as a DataFrame and not a task?
j
To test the result of a task I believe you need run the flow and then can test based off of that state. e.g.:
Copy code
with Flow("task-results") as flow:
    v = get_value()

state = flow.run()

assert state.result[v].result == ...
j
@Crawford Collins Just to add to what @josh said: think of the
with Flow()...
code as defining the structure of the Flow. Without having ever run the Flow yet, there aren't any results available from your tasks, i.e.
assert df...
doesn't give what you might expect since
df
is only a placeholder in the definition of the flow. Once you run your Flow, then you can examine the results of a Flow run. (This difference between a Flow and a Flow run can be a little confusing at first but once you understand it, it'll make sense.)
upvote 3
c
thanks. @josh @Joe Schmid this all makes sense.
j
If you're just trying to test individual task functions (in the absence of a flow), you could also call the task manually with the
.run
attribute:
Copy code
@task
def my_function(a, b):
    ...

res = my_function.run(a, b)
assert res.isna().sum() == 0
upvote 3