<#2793 [BUG] Flytkit Named Tuples cannot access be...
# flyte-github
a
#2793 [BUG] Flytkit Named Tuples cannot access be accessed if there is only one attribute Issue created by brandon-segal Description: In Flytekit there is no way to mock a named tuple that only has a single member. Mocking a situation like the following results in a
AttributeError: 'Promise' object has no attribute 'uri'
error.
Copy code
class GenerateOutputs(NamedTuple):
        uri: str
    
@reference_task(
    ...
)
def generate(
    input:str 
) -> GenerateOutputs:
    ... 
    
@workflow
def my_wf(
   input="default_input"
) -> str:
    output = generate(
      input:str=input
    )
    return output.uri

class TestNamedTuple(TestCase):
    def test_run_workflow(self):
        with task_mock(generate) as fake_generate:
            fake_generate.return_value = GenerateOutputs(uri="test_uri")
            uri = my_wf()
            self.assertIsNotNone(uri)
Ideally we would be able to do something like the following which we can do when the NamedTuple has two attributes:
Copy code
from typing import NamedTuple
from unittest import TestCase
from flytekit.testing import task_mock
from flytekit import workflow,reference_task

class GenerateOutputs(NamedTuple):
    uri: str
    other_thing:str

@reference_task(
    ...
)
def generate(
    input:str 
) -> GenerateOutputs:
    ... 

@workflow
def my_wf(
    input:str="default_input"
) -> str:
    output = generate(
        input=input
    )
    # Could similarly unpack the tuple and just return the uri 
    return output.uri


class TestNamedTuple(TestCase):
    def test_run_workflow(self):
        with task_mock(generate) as fake_generate:
            fake_generate.return_value = GenerateOutputs(uri="test_uri",other_thing="test")
            uri = my_wf()
            self.assertIsNotNone(uri)
flyteorg/flyte