0

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.

vinay polisetti
  • 374
  • 1
  • 3
  • 15

3 Answers3

1

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.

Demian Brecht
  • 21,135
  • 5
  • 42
  • 46
1

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.

dbn
  • 13,144
  • 3
  • 60
  • 86
0

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]