I have searched and cannot seem to find the answer to my issue. Iām hoping someone can help.
Here is a slimmed down version of my code. I have it within a unit test TestCase
class. I open three books, one of which is an xlsm
file (wb2
), do some processing, and then save the wb2
file with another name and close all three workbooks.
What's happening is that all three workbooks are closing, but there still remains an instance of Excel open. Like, an empty shell with nothing in it. I searched and found the kill()
method, but that is not killing it (whether I use self.xw.App().kill()
or just xw.App().kill())
. Also, I print out all of the open apps and it returns an empty list. So, I don't know what this instance remaining is all about and why it's not getting killed. BTW, I am using Excel 365. Thanks in advance.
import xlwings as xw
class TestClass(unittest.TestCase):
def test_xltest(self):
#Open 3 separate workbooks
self.wb1 = xw.Book(workbook1)
self.wb2 = xw.Book(workbook2)
self.wb3 = xw.Book(workbook3)
#Do some processing here
def tearDown(self):
self.wb1.close()
self.wb2.save(self.newDirectoryPath)
self.wb2.close()
self.wb3.close()
print (xw.apps)
self.xw.App().kill()
if __name__ == "__main__":
unittest.main()