@@ -36,11 +36,11 @@ class TestCase:
3636
3737 def __init__ (self , check , partition , environ ):
3838 self ._check_orig = check
39- self ._check = copy .deepcopy (check )
40- self ._partition = copy .deepcopy (partition )
41- self ._environ = copy .deepcopy (environ )
42- self ._check ._case = weakref .ref (self )
39+ self ._check = check
40+ self ._partition = partition
41+ self ._environ = environ
4342 self ._deps = []
43+ self ._is_ready = False
4444
4545 # Incoming dependencies
4646 self .in_degree = 0
@@ -72,6 +72,15 @@ def __repr__(self):
7272 e = self .environ .name if self .environ else None
7373 return f'({ c !r} , { p !r} , { e !r} )'
7474
75+ def prepare (self ):
76+ '''Prepare test case for sending down the test pipeline'''
77+ if self ._is_ready :
78+ return
79+
80+ self ._check = copy .deepcopy (self ._check )
81+ self ._check ._case = weakref .ref (self )
82+ self ._is_ready = True
83+
7584 @property
7685 def check (self ):
7786 return self ._check
@@ -97,8 +106,14 @@ def clone(self):
97106 return TestCase (self ._check_orig , self ._partition , self ._environ )
98107
99108
100- def generate_testcases (checks ):
101- '''Generate concrete test cases from checks.'''
109+ def generate_testcases (checks , prepare = False ):
110+ '''Generate concrete test cases from checks.
111+
112+ If `prepare` is true then each of the cases will also be prepared for
113+ being sent to the test pipeline. Note that setting this to true may slow down
114+ the test case generation.
115+
116+ '''
102117
103118 rt = runtime .runtime ()
104119 cases = []
@@ -107,7 +122,11 @@ def generate_testcases(checks):
107122 c .valid_prog_environs )
108123 for part , environs in valid_comb .items ():
109124 for env in environs :
110- cases .append (TestCase (c , part , env ))
125+ case = TestCase (c , part , env )
126+ if prepare :
127+ case .prepare ()
128+
129+ cases .append (case )
111130
112131 return cases
113132
@@ -295,6 +314,7 @@ def __exit__(this, exc_type, exc_value, traceback):
295314 raise TaskExit from e
296315
297316 def setup (self , * args , ** kwargs ):
317+ self .testcase .prepare ()
298318 self ._safe_call (self .check .setup , * args , ** kwargs )
299319 self ._notify_listeners ('on_task_setup' )
300320
0 commit comments