summaryrefslogtreecommitdiff
path: root/coverage/control.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-09-24 06:48:58 -0400
committerNed Batchelder <ned@nedbatchelder.com>2018-09-24 06:48:58 -0400
commit545a47cc59b88e5b51852256e6cc1602850d001b (patch)
tree5ea7e435ea483bd176937cf80f4b9b6c43d9e9fd /coverage/control.py
parentbd36f540f4ab9a7155da3993f5d7d48b10112900 (diff)
parentb5d5aa99ebcfa140bc779301b22a0866903b6342 (diff)
downloadpython-coveragepy-git-545a47cc59b88e5b51852256e6cc1602850d001b.tar.gz
Merge branch 'nedbat/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 678a7b3b..4f2afda0 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.