@@ -129,12 +129,9 @@ def test_discover_tests_pytest_with_temp_dir_root():
129129        # Check if the dummy test file is discovered 
130130        assert  len (discovered_tests ) ==  1 
131131        assert  len (discovered_tests ["dummy_code.dummy_function" ]) ==  2 
132-         assert  discovered_tests ["dummy_code.dummy_function" ][0 ].tests_in_file .test_file  ==  test_file_path 
133-         assert  discovered_tests ["dummy_code.dummy_function" ][1 ].tests_in_file .test_file  ==  test_file_path 
134-         assert  {
135-             discovered_tests ["dummy_code.dummy_function" ][0 ].tests_in_file .test_function ,
136-             discovered_tests ["dummy_code.dummy_function" ][1 ].tests_in_file .test_function ,
137-         } ==  {"test_dummy_parametrized_function[True]" , "test_dummy_function" }
132+         dummy_tests  =  discovered_tests ["dummy_code.dummy_function" ]
133+         assert  all (test .tests_in_file .test_file  ==  test_file_path  for  test  in  dummy_tests )
134+         assert  {test .tests_in_file .test_function  for  test  in  dummy_tests } ==  {"test_dummy_parametrized_function[True]" , "test_dummy_function" }
138135
139136
140137def  test_discover_tests_pytest_with_multi_level_dirs ():
@@ -201,13 +198,13 @@ def test_discover_tests_pytest_with_multi_level_dirs():
201198
202199        # Check if the test files at all levels are discovered 
203200        assert  len (discovered_tests ) ==  3 
204-         assert  discovered_tests ["root_code.root_function" ][ 0 ] .tests_in_file .test_file  ==  root_test_file_path 
201+         assert  next ( iter ( discovered_tests ["root_code.root_function" ])) .tests_in_file .test_file  ==  root_test_file_path 
205202        assert  (
206-             discovered_tests ["level1.level1_code.level1_function" ][ 0 ] .tests_in_file .test_file  ==  level1_test_file_path 
203+             next ( iter ( discovered_tests ["level1.level1_code.level1_function" ])) .tests_in_file .test_file  ==  level1_test_file_path 
207204        )
208205
209206        assert  (
210-             discovered_tests ["level1.level2.level2_code.level2_function" ][ 0 ] .tests_in_file .test_file 
207+             next ( iter ( discovered_tests ["level1.level2.level2_code.level2_function" ])) .tests_in_file .test_file 
211208            ==  level2_test_file_path 
212209        )
213210
@@ -291,17 +288,17 @@ def test_discover_tests_pytest_dirs():
291288
292289        # Check if the test files at all levels are discovered 
293290        assert  len (discovered_tests ) ==  4 
294-         assert  discovered_tests ["root_code.root_function" ][ 0 ] .tests_in_file .test_file  ==  root_test_file_path 
291+         assert  next ( iter ( discovered_tests ["root_code.root_function" ])) .tests_in_file .test_file  ==  root_test_file_path 
295292        assert  (
296-             discovered_tests ["level1.level1_code.level1_function" ][ 0 ] .tests_in_file .test_file  ==  level1_test_file_path 
293+             next ( iter ( discovered_tests ["level1.level1_code.level1_function" ])) .tests_in_file .test_file  ==  level1_test_file_path 
297294        )
298295        assert  (
299-             discovered_tests ["level1.level2.level2_code.level2_function" ][ 0 ] .tests_in_file .test_file 
296+             next ( iter ( discovered_tests ["level1.level2.level2_code.level2_function" ])) .tests_in_file .test_file 
300297            ==  level2_test_file_path 
301298        )
302299
303300        assert  (
304-             discovered_tests ["level1.level3.level3_code.level3_function" ][ 0 ] .tests_in_file .test_file 
301+             next ( iter ( discovered_tests ["level1.level3.level3_code.level3_function" ])) .tests_in_file .test_file 
305302            ==  level3_test_file_path 
306303        )
307304
@@ -337,7 +334,7 @@ def test_discover_tests_pytest_with_class():
337334
338335        # Check if the test class and method are discovered 
339336        assert  len (discovered_tests ) ==  1 
340-         assert  discovered_tests ["some_class_code.SomeClass.some_method" ][ 0 ] .tests_in_file .test_file  ==  test_file_path 
337+         assert  next ( iter ( discovered_tests ["some_class_code.SomeClass.some_method" ])) .tests_in_file .test_file  ==  test_file_path 
341338
342339
343340def  test_discover_tests_pytest_with_double_nested_directories ():
@@ -376,9 +373,7 @@ def test_discover_tests_pytest_with_double_nested_directories():
376373        # Check if the test class and method are discovered 
377374        assert  len (discovered_tests ) ==  1 
378375        assert  (
379-             discovered_tests ["nested.more_nested.nested_class_code.NestedClass.nested_method" ][
380-                 0 
381-             ].tests_in_file .test_file 
376+             next (iter (discovered_tests ["nested.more_nested.nested_class_code.NestedClass.nested_method" ])).tests_in_file .test_file 
382377            ==  test_file_path 
383378        )
384379
@@ -425,7 +420,7 @@ def test_discover_tests_with_code_in_dir_and_test_in_subdir():
425420
426421        # Check if the test file is discovered and associated with the code file 
427422        assert  len (discovered_tests ) ==  1 
428-         assert  discovered_tests ["code.some_code.some_function" ][ 0 ] .tests_in_file .test_file  ==  test_file_path 
423+         assert  next ( iter ( discovered_tests ["code.some_code.some_function" ])) .tests_in_file .test_file  ==  test_file_path 
429424
430425
431426def  test_discover_tests_pytest_with_nested_class ():
@@ -465,7 +460,7 @@ def test_discover_tests_pytest_with_nested_class():
465460        # Check if the test for the nested class method is discovered 
466461        assert  len (discovered_tests ) ==  1 
467462        assert  (
468-             discovered_tests ["nested_class_code.OuterClass.InnerClass.inner_method" ][ 0 ] .tests_in_file .test_file 
463+             next ( iter ( discovered_tests ["nested_class_code.OuterClass.InnerClass.inner_method" ])) .tests_in_file .test_file 
469464            ==  test_file_path 
470465        )
471466
@@ -504,7 +499,7 @@ def test_discover_tests_pytest_separate_moduledir():
504499
505500        # Check if the test for the nested class method is discovered 
506501        assert  len (discovered_tests ) ==  1 
507-         assert  discovered_tests ["mypackage.code.find_common_tags" ][ 0 ] .tests_in_file .test_file  ==  test_file_path 
502+         assert  next ( iter ( discovered_tests ["mypackage.code.find_common_tags" ])) .tests_in_file .test_file  ==  test_file_path 
508503
509504
510505def  test_unittest_discovery_with_pytest ():
@@ -548,8 +543,9 @@ def test_add(self):
548543        assert  len (discovered_tests ) ==  1 
549544        assert  "calculator.Calculator.add"  in  discovered_tests 
550545        assert  len (discovered_tests ["calculator.Calculator.add" ]) ==  1 
551-         assert  discovered_tests ["calculator.Calculator.add" ][0 ].tests_in_file .test_file  ==  test_file_path 
552-         assert  discovered_tests ["calculator.Calculator.add" ][0 ].tests_in_file .test_function  ==  "test_add" 
546+         calculator_test  =  next (iter (discovered_tests ["calculator.Calculator.add" ]))
547+         assert  calculator_test .tests_in_file .test_file  ==  test_file_path 
548+         assert  calculator_test .tests_in_file .test_function  ==  "test_add" 
553549
554550
555551def  test_unittest_discovery_with_pytest_parent_class ():
@@ -615,8 +611,9 @@ def test_add(self):
615611        assert  len (discovered_tests ) ==  2 
616612        assert  "calculator.Calculator.add"  in  discovered_tests 
617613        assert  len (discovered_tests ["calculator.Calculator.add" ]) ==  1 
618-         assert  discovered_tests ["calculator.Calculator.add" ][0 ].tests_in_file .test_file  ==  test_file_path 
619-         assert  discovered_tests ["calculator.Calculator.add" ][0 ].tests_in_file .test_function  ==  "test_add" 
614+         calculator_test  =  next (iter (discovered_tests ["calculator.Calculator.add" ]))
615+         assert  calculator_test .tests_in_file .test_file  ==  test_file_path 
616+         assert  calculator_test .tests_in_file .test_function  ==  "test_add" 
620617
621618
622619def  test_unittest_discovery_with_pytest_private ():
@@ -712,9 +709,10 @@ def test_add_with_parameters(self):
712709        assert  len (discovered_tests ) ==  1 
713710        assert  "calculator.Calculator.add"  in  discovered_tests 
714711        assert  len (discovered_tests ["calculator.Calculator.add" ]) ==  1 
715-         assert  discovered_tests ["calculator.Calculator.add" ][0 ].tests_in_file .test_file  ==  test_file_path 
712+         calculator_test  =  next (iter (discovered_tests ["calculator.Calculator.add" ]))
713+         assert  calculator_test .tests_in_file .test_file  ==  test_file_path 
716714        assert  (
717-             discovered_tests [ "calculator.Calculator.add" ][ 0 ] .tests_in_file .test_function  ==  "test_add_with_parameters" 
715+             calculator_test .tests_in_file .test_function  ==  "test_add_with_parameters" 
718716        )
719717
720718
0 commit comments