Skip to content

Commit 6ab6cd8

Browse files
committed
Fix test_oclint_plist_cleanup to change to tmpdir before cleanup
OCLintCmd.cleanup_files() uses os.getcwd() to list files, so the test must chdir to the temp directory before calling it. Without this, os.getcwd() fails with FileNotFoundError when the current directory doesn't exist or has been deleted. Changes: - Save original cwd - chdir to tmpdir before calling cleanup_files() - Restore original cwd in finally block Fixes Ubuntu CI test failure.
1 parent c7a4512 commit 6ab6cd8

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

tests/test_edge_cases.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,24 +269,29 @@ def test_oclint_version_detection(self):
269269
@pytest.mark.skipif(os.name == "nt", reason="OCLint not available on Windows")
270270
def test_oclint_plist_cleanup(self):
271271
"""Test that OCLint cleans up generated .plist files."""
272+
original_cwd = os.getcwd()
272273
with tempfile.TemporaryDirectory() as tmpdir:
273-
test_file = os.path.join(tmpdir, "test.c")
274-
with open(test_file, "w") as f:
275-
f.write("int main() { return 0; }\n")
274+
try:
275+
os.chdir(tmpdir)
276+
test_file = os.path.join(tmpdir, "test.c")
277+
with open(test_file, "w") as f:
278+
f.write("int main() { return 0; }\n")
276279

277-
plist_file = os.path.join(tmpdir, "test.plist")
278-
with open(plist_file, "w") as f:
279-
f.write("fake plist content\n")
280+
plist_file = os.path.join(tmpdir, "test.plist")
281+
with open(plist_file, "w") as f:
282+
f.write("fake plist content\n")
280283

281-
existing_files = os.listdir(tmpdir)
282-
assert "test.plist" in existing_files
284+
existing_files = os.listdir(tmpdir)
285+
assert "test.plist" in existing_files
283286

284-
# Simulate cleanup
285-
OCLintCmd.cleanup_files(existing_files)
287+
# Simulate cleanup - cleanup_files uses os.getcwd()
288+
OCLintCmd.cleanup_files(existing_files)
286289

287-
# In actual use, cleanup removes plist files created by oclint
288-
# Here we just test the method exists and can be called
289-
assert hasattr(OCLintCmd, "cleanup_files")
290+
# In actual use, cleanup removes plist files created by oclint
291+
# Here we just test the method exists and can be called
292+
assert hasattr(OCLintCmd, "cleanup_files")
293+
finally:
294+
os.chdir(original_cwd)
290295

291296

292297
class TestIncludeWhatYouUse:

0 commit comments

Comments
 (0)