I am using Python Nose and would like to print the type of the test ran, like whether it is a Doctest or unittest or so? How can this be done?
Thanks.
I am using Python Nose and would like to print the type of the test ran, like whether it is a Doctest or unittest or so? How can this be done?
Thanks.
Using --with-doctests
implies that you're running doctests. Anything outside of a doctest can be considered a unit test. AFAIK, they're not mutually exclusive, so you can't strictly tell which you're running if you've enabled --with-doctests
.
Having said that, doctests generally are a form of unit test, so I'm not quite sure what end you're trying to achieve with this.
You can create your own plugin to change the printed name of the test. Then, when you use the verbose flag the test type will print. Try something like this:
from nose.plugins import Plugin
import doctest
class CustomName(Plugin):
def describeTest(self, test):
if isinstance(test, doctest.DocTestCase):
return "Doctest: %s" % test
else:
return "Unittest: %s" % test
After installing it, run it like:
nosetests --with-customname -sv test_directory
Be warned, this is untested.
This might be a little fragile. But note that nosetests are just on top of unittest
import inspect
def is_nose_test():
assert "nose" in inspect.stack()[1][1]