From 7632f4c60b5fbc856beea7607ce2b448f6b5bbbc Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 20 Mar 2010 08:27:30 -0400 Subject: Calculate the pid suffix for data files at the end of the process so that programs calling os.fork will collect data from both child and parent. Fixes issue #56. --- coverage/data.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'coverage/data.py') diff --git a/coverage/data.py b/coverage/data.py index 9359af12..1b883750 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -21,22 +21,11 @@ class CoverageData(object): """ - # Name of the data file (unless environment variable is set). - filename_default = ".coverage" - - # Environment variable naming the data file. - filename_env = "COVERAGE_FILE" - - def __init__(self, basename=None, suffix=None, collector=None): + def __init__(self, basename=None, collector=None): """Create a CoverageData. `basename` is the name of the file to use for storing data. - `suffix` is a suffix to append to the base file name. This can be used - for multiple or parallel execution, so that many coverage data files - can exist simultaneously. A dot will be used to join the base name and - the suffix. - `collector` is a string describing the coverage measurement software. """ @@ -47,8 +36,6 @@ class CoverageData(object): # Construct the filename that will be used for data file storage, if we # ever do any file storage. self.filename = basename or ".coverage" - if suffix: - self.filename += "." + suffix self.filename = os.path.abspath(self.filename) # A map from canonical Python source file name to a dictionary in @@ -80,10 +67,20 @@ class CoverageData(object): else: self.lines, self.arcs = {}, {} - def write(self): - """Write the collected coverage data to a file.""" + def write(self, suffix=None): + """Write the collected coverage data to a file. + + `suffix` is a suffix to append to the base file name. This can be used + for multiple or parallel execution, so that many coverage data files + can exist simultaneously. A dot will be used to join the base name and + the suffix. + + """ if self.use_file: - self.write_file(self.filename) + filename = self.filename + if suffix: + filename += "." + suffix + self.write_file(filename) def erase(self): """Erase the data, both in this object, and from its file storage.""" -- cgit v1.2.1