Index: pymatgen/tests/io/qchem/test_inputs.py
===================================================================
--- pymatgen.orig/tests/io/qchem/test_inputs.py	2025-02-20 11:46:18.538811075 +0100
+++ pymatgen/tests/io/qchem/test_inputs.py	2025-02-20 11:46:18.534811318 +0100
@@ -19,7 +19,12 @@
 __email__ = "samblau1@gmail.com"
 __credits__ = "Xiaohui Qu"
 
+@pytest.fixture(scope="class")
+def tmp_path_write(request, tmp_path_factory):
+    tmp_path = tmp_path_factory.mktemp(request.cls.__name__ + "_write")
+    request.cls.tmp_path = tmp_path
 
+@pytest.mark.usefixtures("tmp_path_write")
 class TestQCInput(PymatgenTest):
     def test_molecule_template(self):
         species = ["C", "O"]
@@ -1229,8 +1234,14 @@
         odd_dict = loadfn(f"{TEST_DIR}/odd.json")
         odd_mol = odd_dict["spec"]["_tasks"][0]["molecule"]
         qcinp = OptSet(odd_mol)
-        qcinp.write_file(f"{TEST_DIR}/test.qin")
-        test_path = f"{TEST_DIR}/test.qin"
+        try:
+            qcinp.write_file(f"{TEST_DIR}/test.qin")
+            test_path = f"{TEST_DIR}/test.qin"
+        except PermissionError:
+            # test files located in non-writable dir
+            # so use tmp_path instead
+            qcinp.write_file(f"{self.tmp_path}/test.qin")
+            test_path = f"{self.tmp_path}/test.qin"
         ref_path = f"{TEST_DIR}/test_ref.qin"
 
         with open(ref_path, encoding="utf-8") as ref_file, open(test_path, encoding="utf-8") as test_file:
@@ -1238,14 +1249,20 @@
                 # By default, if this statement fails the offending line will be printed
                 assert l_test == l_ref
 
-        os.remove(f"{TEST_DIR}/test.qin")
+        os.remove(test_path)
 
     def test_write_file_from_opt_set_with_vdw(self):
         odd_dict = loadfn(f"{TEST_DIR}/odd.json")
         odd_mol = odd_dict["spec"]["_tasks"][0]["molecule"]
         qcinp = OptSet(odd_mol, overwrite_inputs={"van_der_waals": {"16": 3.14159}})
-        qcinp.write_file(f"{TEST_DIR}/test_vdw.qin")
-        test_path = f"{TEST_DIR}/test_vdw.qin"
+        try:
+            qcinp.write_file(f"{TEST_DIR}/test_vdw.qin")
+            test_path = f"{TEST_DIR}/test_vdw.qin"
+        except PermissionError:
+            # test files located in non-writable dir
+            # so use tmp_path instead
+            qcinp.write_file(f"{self.tmp_path}/test_vdw.qin")
+            test_path = f"{self.tmp_path}/test_vdw.qin"
         ref_path = f"{TEST_DIR}/test_ref_vdw.qin"
 
         with open(ref_path, encoding="utf-8") as ref_file, open(test_path, encoding="utf-8") as test_file:
@@ -1253,7 +1270,7 @@
                 # By default, if this statement fails the offending line will be printed
                 assert l_test == l_ref
 
-        os.remove(f"{TEST_DIR}/test_vdw.qin")
+        os.remove(test_path)
 
     def test_read_write_nbo7(self):
         test_path = f"{TEST_DIR}/test_nbo7.qin"
