11"""Provide necessary information that is needed for a specific test."""
2- import functools
32import pathlib
43from typing import Any , Callable , Optional , Dict , Union
54
1110from nuts .helpers .result import NutsResult
1211
1312
13+ _TransformedResult = Dict [str , Any ]
14+
15+
1416class NutsContext :
1517 """
1618 Base context class. Holds all necessary information that is needed for a specific test.
@@ -20,6 +22,7 @@ class NutsContext:
2022
2123 def __init__ (self , nuts_parameters : Any = None ):
2224 self .nuts_parameters = nuts_parameters or {}
25+ self ._cached_result : Optional [_TransformedResult ] = None
2326
2427 def initialize (self ) -> None :
2528 """Initialize dependencies for this context after it has been created."""
@@ -44,21 +47,23 @@ def general_result(self) -> Any:
4447 """
4548 raise NotImplementedError
4649
47- def transform_result (self , general_result : Any ) -> Dict [ str , Any ] :
50+ def transform_result (self , general_result : Any ) -> _TransformedResult :
4851 """
4952 :param general_result: raw result
5053 :return: processed result ready to be passed to a test
5154 """
5255 raise NotImplementedError
5356
54- @functools . cached_property
55- def transformed_result (self ) -> Dict [ str , Any ] :
57+ @property
58+ def transformed_result (self ) -> _TransformedResult :
5659 """
5760 The (processed) results of the network task, ready to be passed on to a test's fixture.
5861 The results are cached, so that general_result does not need to be called multiple times as it might
5962 access the network.
6063 """
61- return self .transform_result (self .general_result ())
64+ if self ._cached_result is None :
65+ self ._cached_result = self .transform_result (self .general_result ())
66+ return self ._cached_result
6267
6368
6469class NornirNutsContext (NutsContext ):
0 commit comments