#python #sicp
To verify the doctest interactions for only a single function, we use a doctest function called run_docstring_examples . This function is
(unfortunately) a bit complicated to call. Its first argument is the function
to test. The second should always be the result of the expression globals() , a built-in function that returns the global environment. The
third argument is True to indicate that we would like "verbose" output: a
catalog of all tests run.
If you want to change selection, open document below and click on "Move attachment"
1.5 Control the
globals function returns a representation of the global environment, which
the interpreter needs in order to evaluate expressions.
>>> from doctest import testmod
>>> testmod()
TestResults(failed=0, attempted=2)
<span>To verify the doctest interactions for only a single function, we use a
doctest function called run_docstring_examples . This function is
(unfortunately) a bit complicated to call. Its first argument is the function
to test. The second should always be the result of the expression
globals() , a built-in function that returns the global environment. The
third argument is True to indicate that we would like "verbose" output: a
catalog of all tests run.
>>> from doctest import run_docstring_examples
>>> run_docstring_examples(sum_naturals, globals(), True)
Finding tests in NoName
Trying:
sum_naturals(10)
Expecti Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details