@@ -1105,7 +1105,8 @@ def test_copytree_to_itself_gives_sensible_error_message(self):
11051105 src_dir = os .path .join (base_dir , "src" )
11061106 os .makedirs (src_dir )
11071107 create_file ((src_dir , "somefilename" ), "somecontent" )
1108- self ._assert_are_the_same_file_is_raised (src_dir , src_dir )
1108+ with self ._assert_are_the_same_file_is_raised ():
1109+ shutil .copytree (src_dir , src_dir , dirs_exist_ok = True )
11091110
11101111 @os_helper .skip_unless_symlink
11111112 def test_copytree_to_backpointing_symlink_gives_sensible_error_message (self ):
@@ -1118,11 +1119,13 @@ def test_copytree_to_backpointing_symlink_gives_sensible_error_message(self):
11181119 some_file = os .path .join (src_dir , "somefilename" )
11191120 create_file (some_file , "somecontent" )
11201121 os .symlink (some_file , os .path .join (target_dir , "somefilename" ))
1121- self ._assert_are_the_same_file_is_raised (src_dir , target_dir )
1122+ with self ._assert_are_the_same_file_is_raised ():
1123+ shutil .copytree (src_dir , target_dir , dirs_exist_ok = True )
11221124
1123- def _assert_are_the_same_file_is_raised (self , src_dir , target_dir ):
1125+ @contextlib .contextmanager
1126+ def _assert_are_the_same_file_is_raised (self ):
11241127 with self .assertRaises (Error ) as cm :
1125- shutil . copytree ( src_dir , target_dir , dirs_exist_ok = True )
1128+ yield
11261129
11271130 self .assertEqual (len (cm .exception .args [0 ]), 1 )
11281131 if sys .platform == "win32" :
0 commit comments