I'd like to automate some tests and log the output of each test into different files, but it seems that all tests outputs are appended into the first log file, instead of separate files. May I know how can I correct this?
What I did is: First, define runthis.cfg which contains all the test config file. Second, execute run.py. It imports class A, for loop and write some log data for each loop
In runthis.cfg
2
prob1.cfg
prob2.cfg
In run.py
from fa import A
def run_it(cfg_data):
cfg = cfg_data.split('\n')
runCount = int(cfg[0])
for i in range(1, runCount+1):
print "\n\nRunning " + cfg[i] + "..."
cA.readProblemInstance(cfg[i])
cA = A()
if __name__ == '__main__':
run_config_file = open('runthis.cfg', 'r')
cfg_data = ''.join(run_config_file.readlines())
run_config_file.close()
run_it(cfg_data)
In fa.py
from datetime import datetime
import time
import logging
class A():
def activateLogFile(self, f):
logging.basicConfig(filename=f, level=logging.INFO)
def readProblemInstance(self, fn):
fn = fn.replace('.', '_')
fn = fn + '_' + datetime.now().strftime('%Y_%m_%d_%H_%M_%S_%f')
self.activateLogFile(fn)
logging.info("%s" %fn)
The output is, in prob1_cfg_2014_04_07_12_39_38_293000,
INFO:root:prob1_cfg_2014_04_07_12_39_38_293000
INFO:root:prob2_cfg_2014_04_07_12_39_38_294000
prob2_cfg_2014_04_07_12_39_38_294000 doesn't exists!