← Back to team overview

sikuli-driver team mailing list archive

[Question #184468]: Class variable in unittest script query

 

New question #184468 on Sikuli:
https://answers.launchpad.net/sikuli/+question/184468

Hi,

I'm writing a number of tests in Sikuli and to make my coding more efficient I want to call my own methods rather than duplicating a lot of code. The problem is that I need to write text to a file in a method that I call. I have declared the file to write to and the code in the method can successfully write to the file but only on the second time the unittest is run. 

1) I run the script, the file is created but is empty. Cannot delete the file becaue it is not closed properly and is locked.
2) I run the script a second time and the string is written to the file created in the first run of the unitscript.

I was wondering if I was missing something in the way I have declared my file variables. My simplified code is below.

def setUp(self):
    pass

def tearDown(self):
    pass

def test_A(self):
    import datetime
    import time

    t = datetime.datetime.now()
    dt = t.strftime('%d%b%Y%H%M')
    self.f = open("c:\\Log\\TestLog[" + dt + "].txt", "a+")

    print " execution 1"
    self.log("write this text to file")

    print "execution 3"
    self.f.close

def log(self,text):
    self.f.write(text)
    print "execution 2"

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.