summaryrefslogtreecommitdiff
path: root/coverage/control.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-09-23 06:44:07 -0400
committerNed Batchelder <ned@nedbatchelder.com>2018-09-23 19:02:21 -0400
commit106828c2cc8bbce1e5fb31c6a89ea3ac025225c1 (patch)
treed25428c8b525941619a2b472d25f309a02189d80 /coverage/control.py
parentb609117ef73ae372f027686b22f13c488c841253 (diff)
downloadpython-coveragepy-git-106828c2cc8bbce1e5fb31c6a89ea3ac025225c1.tar.gz
Dynamic contexts
Diffstat (limited to 'coverage/control.py')
-rw-r--r--coverage/control.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/coverage/control.py b/coverage/control.py
index f7d97cf6..23f0cbdd 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -347,9 +347,19 @@ class Coverage(object):
# it for the main process.
self.config.parallel = True
+ if self.config.dynamic_context is None:
+ should_start_context = None
+ elif self.config.dynamic_context == "test_function":
+ should_start_context = should_start_context_test_function
+ else:
+ raise CoverageException(
+ "Don't understand dynamic_context setting: {!r}".format(self.config.dynamic_context)
+ )
+
self._collector = Collector(
should_trace=self._should_trace,
check_include=self._check_include_omit_etc,
+ should_start_context=should_start_context,
timid=self.config.timid,
branch=self.config.branch,
warn=self._warn,
@@ -886,6 +896,16 @@ if int(os.environ.get("COVERAGE_DEBUG_CALLS", 0)): # pragma: debugg
Coverage = decorate_methods(show_calls(show_args=True), butnot=['get_data'])(Coverage)
+def should_start_context_test_function(frame):
+ """Who-Tests-What hack: Determine whether this frame begins a new who-context."""
+ with open("/tmp/ssc.txt", "a") as f:
+ f.write("hello\n")
+ fn_name = frame.f_code.co_name
+ if fn_name.startswith("test"):
+ return fn_name
+ return None
+
+
def process_startup():
"""Call this at Python start-up to perhaps measure coverage.