@@ -14,28 +14,34 @@ def test_config():
1414 """Create a mock TestConfig for testing."""
1515 config = Mock (spec = TestConfig )
1616 config .project_root_path = Path ("/project" )
17+ config .test_framework = "pytest"
18+ config .tests_project_rootdir = Path ("/project/tests" )
1719 config .tests_root = Path ("/project/tests" )
1820 return config
1921
2022
21- @pytest .fixture
22- def sample_invocation_id ():
23- """Create a sample InvocationId for testing."""
24- return InvocationId (
25- test_module_path = "tests.test_module" ,
26- test_class_name = "TestClass" ,
27- test_function_name = "test_function" ,
28- )
29-
30-
31- @pytest .fixture
32- def sample_invocation_id_no_class ():
33- """Create a sample InvocationId without class for testing."""
34- return InvocationId (
35- test_module_path = "tests.test_module" ,
36- test_class_name = None ,
37- test_function_name = "test_function" ,
38- )
23+ # @pytest.fixture
24+ # def sample_invocation_id():
25+ # """Create a sample InvocationId for testing."""
26+ # return InvocationId(
27+ # test_module_path="test_module_path",
28+ # test_class_name="test_class_name",
29+ # test_function_name="test_function_name",
30+ # function_getting_tested="function_getting_tested",
31+ # iteration_id="0",
32+ # )
33+ #
34+ #
35+ # @pytest.fixture
36+ # def sample_invocation_id_no_class():
37+ # """Create a sample InvocationId without class for testing."""
38+ # return InvocationId(
39+ # test_module_path="test_module_path",
40+ # test_class_name=None,
41+ # test_function_name="test_function_name",
42+ # function_getting_tested="function_getting_tested",
43+ # iteration_id="0",
44+ # )
3945
4046
4147class TestAddRuntimeCommentsToGeneratedTests :
@@ -60,6 +66,8 @@ def test_add_runtime_comments_simple_function(self, test_config):
6066 test_module_path = "tests.test_module" ,
6167 test_class_name = None ,
6268 test_function_name = "test_function" ,
69+ function_getting_tested = "some_function" ,
70+ iteration_id = "0" ,
6371 )
6472
6573 original_runtimes = {invocation_id : [1000000000 , 1200000000 ]} # 1s, 1.2s in nanoseconds
@@ -70,7 +78,7 @@ def test_add_runtime_comments_simple_function(self, test_config):
7078 )
7179
7280 expected_source = '''def test_function():
73- codeflash_output = some_function() # 1.00s -> 500.00ms (50 .00%)
81+ codeflash_output = some_function() # 1.00s -> 500ms (100 .00%)
7482 assert codeflash_output == expected
7583'''
7684
@@ -99,6 +107,9 @@ def test_function(self):
99107 test_module_path = "tests.test_module" ,
100108 test_class_name = "TestClass" ,
101109 test_function_name = "test_function" ,
110+ function_getting_tested = "some_function" ,
111+ iteration_id = "0" ,
112+
102113 )
103114
104115 original_runtimes = {invocation_id : [2000000000 ]} # 2s in nanoseconds
@@ -110,7 +121,7 @@ def test_function(self):
110121
111122 expected_source = '''class TestClass:
112123 def test_function(self):
113- codeflash_output = some_function() # 2.00s -> 1.00s (50 .00%)
124+ codeflash_output = some_function() # 2.00s -> 1.00s (100 .00%)
114125 assert codeflash_output == expected
115126'''
116127
@@ -141,6 +152,8 @@ def test_add_runtime_comments_multiple_assignments(self, test_config):
141152 test_module_path = "tests.test_module" ,
142153 test_class_name = None ,
143154 test_function_name = "test_function" ,
155+ function_getting_tested = "some_function" ,
156+ iteration_id = "0" ,
144157 )
145158
146159 original_runtimes = {invocation_id : [1500000000 ]} # 1.5s in nanoseconds
@@ -152,9 +165,9 @@ def test_add_runtime_comments_multiple_assignments(self, test_config):
152165
153166 expected_source = '''def test_function():
154167 setup_data = prepare_test()
155- codeflash_output = some_function() # 1.50s -> 750.00ms (50 .00%)
168+ codeflash_output = some_function() # 1.50s -> 750ms (100 .00%)
156169 assert codeflash_output == expected
157- codeflash_output = another_function() # 1.50s -> 750.00ms (50 .00%)
170+ codeflash_output = another_function() # 1.50s -> 750ms (100 .00%)
158171 assert codeflash_output == expected2
159172'''
160173
@@ -183,6 +196,8 @@ def test_add_runtime_comments_no_matching_runtimes(self, test_config):
183196 test_module_path = "tests.other_module" ,
184197 test_class_name = None ,
185198 test_function_name = "other_function" ,
199+ function_getting_tested = "some_other_function" ,
200+ iteration_id = "0" ,
186201 )
187202
188203 original_runtimes = {invocation_id : [1000000000 ]}
@@ -217,6 +232,8 @@ def test_add_runtime_comments_no_codeflash_output(self, test_config):
217232 test_module_path = "tests.test_module" ,
218233 test_class_name = None ,
219234 test_function_name = "test_function" ,
235+ function_getting_tested = "some_function" ,
236+ iteration_id = "0" ,
220237 )
221238
222239 original_runtimes = {invocation_id : [1000000000 ]}
@@ -264,12 +281,16 @@ def test_add_runtime_comments_multiple_tests(self, test_config):
264281 test_module_path = "tests.test_module1" ,
265282 test_class_name = None ,
266283 test_function_name = "test_function1" ,
284+ function_getting_tested = "some_function" ,
285+ iteration_id = "0" ,
267286 )
268287
269288 invocation_id2 = InvocationId (
270289 test_module_path = "tests.test_module2" ,
271290 test_class_name = None ,
272291 test_function_name = "test_function2" ,
292+ function_getting_tested = "another_function" ,
293+ iteration_id = "0" ,
273294 )
274295
275296 original_runtimes = {
@@ -286,12 +307,12 @@ def test_add_runtime_comments_multiple_tests(self, test_config):
286307 )
287308
288309 expected_source1 = '''def test_function1():
289- codeflash_output = some_function() # 1.00s -> 500.00ms (50 .00%)
310+ codeflash_output = some_function() # 1.00s -> 500ms (100 .00%)
290311 assert codeflash_output == expected
291312'''
292313
293314 expected_source2 = '''def test_function2():
294- codeflash_output = another_function() # 2.00s -> 800.00ms (60 .00%)
315+ codeflash_output = another_function() # 2.00s -> 800ms (150 .00%)
295316 assert codeflash_output == expected
296317'''
297318
@@ -320,6 +341,8 @@ def test_add_runtime_comments_performance_regression(self, test_config):
320341 test_module_path = "tests.test_module" ,
321342 test_class_name = None ,
322343 test_function_name = "test_function" ,
344+ function_getting_tested = "some_function" ,
345+ iteration_id = "0" ,
323346 )
324347
325348 original_runtimes = {invocation_id : [1000000000 ]} # 1s
@@ -330,7 +353,7 @@ def test_add_runtime_comments_performance_regression(self, test_config):
330353 )
331354
332355 expected_source = '''def test_function():
333- codeflash_output = some_function() # 1.00s -> 1.50s (-50.00 %)
356+ codeflash_output = some_function() # 1.00s -> 1.50s (-33.33 %)
334357 assert codeflash_output == expected
335358'''
336359
0 commit comments