1919"""
2020
2121import os
22+ import uuid
2223import warnings
2324from contextlib import contextmanager
2425from pathlib import Path
@@ -1130,9 +1131,11 @@ def test_live_upload_download_via_instance(
11301131 osw_obj = osw .express .OswExpress (
11311132 domain = wiki_domain , cred_filepath = cred_filepath
11321133 )
1133- # Create dummy file
1134- source_file = Path .cwd () / "test_instance_upload.txt"
1135- source_file .write_text ("Instance upload test content" )
1134+ # Create dummy file; unique name/content per run so leftovers
1135+ # on the shared test wiki never collide with a re-upload
1136+ uid = uuid .uuid4 ().hex [:8 ]
1137+ source_file = Path .cwd () / f"test_instance_upload_{ uid } .txt"
1138+ source_file .write_text (f"Instance upload test content { uid } " )
11361139
11371140 try :
11381141 # Upload via instance method
@@ -1146,7 +1149,9 @@ def test_live_upload_download_via_instance(
11461149 overwrite = True ,
11471150 )
11481151 assert local_file .path .exists ()
1149- assert local_file .path .read_text () == "Instance upload test content"
1152+ assert local_file .path .read_text () == (
1153+ f"Instance upload test content { uid } "
1154+ )
11501155
11511156 # Cleanup
11521157 local_file .close ()
@@ -1175,14 +1180,22 @@ def test_live_upload_with_target_fpt(
11751180 osw_obj = osw .express .OswExpress (
11761181 domain = wiki_domain , cred_filepath = cred_filepath
11771182 )
1178- source_file = Path .cwd () / "test_target_fpt_upload.txt"
1179- source_file .write_text ("Target FPT test content" )
1180-
1183+ # Unique name and content per run: the shared test wiki keeps
1184+ # pages between runs, and re-uploading identical content raises
1185+ # a fileexists-no-change API error.
1186+ uid = uuid .uuid4 ().hex [:8 ]
1187+ content = f"Target FPT test content { uid } "
1188+ source_file = Path .cwd () / f"test_target_fpt_upload_{ uid } .txt"
1189+ source_file .write_text (content )
1190+ title = f"File:TestTargetFptUpload{ uid } .txt"
1191+
1192+ wiki_file = None
1193+ local_file = None
11811194 try :
11821195 wiki_file = osw_obj .upload_file (
11831196 source = source_file ,
1184- url_or_title = "File:TestTargetFptUpload.txt" ,
1185- target_fpt = "File:TestTargetFptUpload.txt" ,
1197+ url_or_title = title ,
1198+ target_fpt = title ,
11861199 )
11871200 assert wiki_file is not None
11881201 assert wiki_file .change_id is not None
@@ -1193,13 +1206,14 @@ def test_live_upload_with_target_fpt(
11931206 url_or_title = wiki_file .url_or_title ,
11941207 overwrite = True ,
11951208 )
1196- assert local_file .path .read_text () == "Target FPT test content"
1197-
1198- # Cleanup
1199- local_file .close ()
1200- local_file .delete ()
1201- wiki_file .delete ()
1209+ assert local_file .path .read_text () == content
12021210 finally :
1211+ # best-effort cleanup so no state leaks onto the shared wiki
1212+ if local_file is not None :
1213+ local_file .close ()
1214+ local_file .delete ()
1215+ if wiki_file is not None :
1216+ wiki_file .delete ()
12031217 if source_file .exists ():
12041218 source_file .unlink ()
12051219 osw_obj .shut_down ()
0 commit comments