diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-05-12 21:12:09 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-05-12 21:12:09 -0400 |
commit | 8d65b505d832ba4d6e4ad8a612c69377303a1772 (patch) | |
tree | 4e0b2940144f73b01a521e290e244fdda697c505 /coverage/control.py | |
parent | 6451321ebefa3e3976f78d4b10298a200b91aecc (diff) | |
download | python-coveragepy-git-8d65b505d832ba4d6e4ad8a612c69377303a1772.tar.gz |
Give the singleton module interface a way to keep the old behavior of auto-loading and -saving data as needed.
Diffstat (limited to 'coverage/control.py')
-rw-r--r-- | coverage/control.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/coverage/control.py b/coverage/control.py index 32e6fad3..dab9eca4 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -14,7 +14,8 @@ class coverage: """Programmatic access to Coverage. """ - def __init__(self, data_file=None, data_suffix=False, cover_pylib=False): + def __init__(self, data_file=None, data_suffix=False, cover_pylib=False, + auto_data=False): """Create a new coverage measurement context. `data_file` is the base name of the data file to use, defaulting to @@ -26,11 +27,17 @@ class coverage: with the Python interpreter is measured. This includes the Python standard library and any packages installed with the interpreter. + If `auto_data` is true, then any existing data file will be read when + coverage measurement starts, and data will be saved automatically when + measurement stops. + """ from coverage.collector import Collector from coverage import __version__ self.cover_pylib = cover_pylib + self.auto_data = auto_data + self.exclude_re = "" self.exclude_list = [] @@ -105,6 +112,11 @@ class coverage: def start(self): """Start measuring code coverage.""" + if self.auto_data: + self.load() + # Save coverage data when Python exits. + import atexit + atexit.register(self.save) self.collector.start() def stop(self): |