[Tutor] doctest: how to test a single function?
Slater Joseph C , PhD, PE
joseph.slater at wright.edu
Wed May 6 16:59:35 CEST 2015
I'm an admitted newb trying to enter the Python community and use Python significantly (versus occassionally). dockets seems to be much more powerful than I can figure out how to tap.
I have a function inside a file that's an embedded test that (currently) works fine. However, the package has a ton of these, and running all of the tests on all functions just to check the changed function is very time consuming. I can't make heads or tails out of what the manual means. I've read section 25.2 and think I understand it, but clearly do not.
What I do is:
>>> import doctest
>>> doctest.run_docstring_examples("functionname",globs[name="filename.py"])
^
SyntaxError: invalid syntax
I've also tried
import filename
help(filename.functionname)
(works fine)
doctest.run_docstring_examples("filename.functionname")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: run_docstring_examples() missing 1 required positional argument: 'globs'
Now, if I do
>>> doctest.run_docstring_examples("sigp.frfestH1",globs=None)
nothing happens.
Everything works fine from a command line:
bash:> python filename.py (I have the end of the file set to run doctest per easily found numerous examples)
except I have a ridiculous lag due to running tests that are unnecessary. Trying to send options doesn't work either
bash:> python -m 'doctest.run__docstring_examples("filename.functionname",globs="")' filename.py
/opt/local/bin/python: Error while finding spec for 'doctest.run__docstring_examples("sigp.frfestH1",globs="")' (<class 'ImportError'>: No module named 'doctest.run__docstring_examples("sigp'; 'doctest' is not a package)
or
bash:> python -m 'doctest.run__docstring_examples("functionname",globs=None)' filename.py
/opt/local/bin/python: Error while finding spec for 'doctest.run__docstring_examples("sigp.frfestH1",globs="")' (<class 'ImportError'>: No module named 'doctest.run__docstring_examples("sigp'; 'doctest' is not a package)
I appreciate your efforts to address my cluelessness.
Thank You,
Joe
More information about the Tutor
mailing list