Я пытаюсь достичь этого результата
| method | | passed | | datetime
| method | | passed | | datetime
| method | | passed | | datetime
| method | | passed | | datetime
Чтобы достичь этого, у меня есть класс XLWriter
class XLWriter:
def __init__(self, file):
self.workbook = load_workbook(file)
self.worksheet = self.workbook['Sheet1']
self.file = file
def write(self, row):
index = 0
try:
# func name, test passed, date
values = [[inspect.stack()[0][3]], True, datetime.date]
columns = [4, 6, 8]
# 3 writes to perform
while index < 2:
cell = self.worksheet.cell(row=row, column=columns[index])
cell.value = values[index]
index += 1
except:
# function name, declare test failed, date
values = [[inspect.stack()[0][3]], False, datetime.date]
columns = [4, 6, 8]
while index < 2:
cell = self.worksheet.cell(row=row, column=columns[index])
cell.value = values[index]
index += 1
def save(self):
self.workbook.save(self.file)
При вызове этого класса из test.py
, как показано ниже
from xlwriter import XLWriter
xl = XLWriter('File.xlsx')
r = self.driver.current_url
self.assertEqual(r, url)
# write to row 14
xl.write(14)
xl.save()
Я встретился со следующей ошибкой ValueError
ValueError: Cannot convert ['write'] to Excel
Я уверен, что это что-то маленькое и глупое, любая помощь очень ценится.
Редактировать
Полный стек ошибок
Error
Traceback (most recent call last):
File "D:\...\xlwriter.py", line 21, in write
cell.value = values[index]
File "D:\...\env\lib\site-packages\openpyxl\cell\cell.py", line 294, in value
self._bind_value(value)
File "D:\...\env\lib\site-packages\openpyxl\cell\cell.py", line 207, in _bind_value
raise ValueError("Cannot convert {0!r} to Excel".format(value))
ValueError: Cannot convert ['write'] to Excel
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\unittest\case.py", line 59, in testPartExecutor
yield
File "C:\Users\...\AppData\Local\Programs\Python\Python37-32\lib\unittest\case.py", line 615, in run
testMethod()
File "D:\...\test.py", line 40, in test
xl.write(14)
File "D:\...\xlwriter.py", line 29, in write
cell.value = values[index]
File "D:\...\env\lib\site-packages\openpyxl\cell\cell.py", line 294, in value
self._bind_value(value)
File "D:\...\env\lib\site-packages\openpyxl\cell\cell.py", line 207, in _bind_value
raise ValueError("Cannot convert {0!r} to Excel".format(value))
ValueError: Cannot convert ['write'] to Excel