summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2022-10-20 14:17:14 -0700
committerNed Batchelder <ned@nedbatchelder.com>2022-10-20 18:00:17 -0700
commitdc996d32a3631740b0b7ba980d3eee28cd726c9c (patch)
tree833a855b0a8bf6c000e15f647fd2e7f6017a90c7
parent4668a92c8d8f467fbe6291fa4f56e96e19709e90 (diff)
downloadpython-coveragepy-git-dc996d32a3631740b0b7ba980d3eee28cd726c9c.tar.gz
docs: add another FAQ
-rw-r--r--doc/faq.rst17
1 files changed, 15 insertions, 2 deletions
diff --git a/doc/faq.rst b/doc/faq.rst
index e2fc2f28..b8c2758c 100644
--- a/doc/faq.rst
+++ b/doc/faq.rst
@@ -23,11 +23,24 @@ If old data is persisting, you can use an explicit ``coverage erase`` command
to clean out the old data.
+Q: Why are my function definitions marked as run when I haven't tested them?
+............................................................................
+
+The ``def`` and ``class`` lines in your Python file are executed when the file
+is imported. Those are the lines that define your functions and classes. They
+run even if you never call the functions. It's the body of the functions that
+will be marked as not executed if you don't test them, not the ``def`` lines.
+
+This can mean that your code has a moderate coverage total even if no tests
+have been written or run. This might seem surprising, but it is accurate: the
+``def`` lines have actually been run.
+
+
Q: Why do the bodies of functions show as executed, but the def lines do not?
.............................................................................
-This happens because coverage.py is started after the functions are defined.
-The definition lines are executed without coverage measurement, then
+If this happens, it's because coverage.py has started after the functions are
+defined. The definition lines are executed without coverage measurement, then
coverage.py is started, then the function is called. This means the body is
measured, but the definition of the function itself is not.