0 comments

doctest support

Neppord has contributed a couple of patches the last few weeks. Apart from some code-cleaning (thanks!) and a bug-fix (even bigger thanks!) he has added doctest-support to pytddmon. Read more on the details of the cool standard Python module doctest here.

Since doctest-tests are ”embedded” in the definition of a function (or class) in Python, the natural thing to do would be to scan all *.py files in the current directory. However, after some discussion, we’ve decided not do to that, based on the rationale that importing (and thus executing) every *.py file in the current directory may lead to unwanted* side effects.

Here’s some code to explain this:

def double(x):
    '''
    >>> double(5)
    10
    '''
    return x*2

If that function is saved in ”test_some.py”, pytddmon will discoverd it automatically, like any unittest-based test.

However, the natural thing is to save it in a code file, not a test file. If you save it to ”unit.py”, pytddmon will not discover it. Instead, you will have to specify that you really want pytddmon to look into that file for tests:

python pyTDDmon.pyw unit.py

The new version can be downloaded via the Download link to the right. It includes Python3 support too!

* Even though the Python convention is to not do things when a module is imported (as opposed to being run as a script) via the following well-known idiom:

if __name__ == '__main__':
    main()

… we consider that knowledge a little bit too non-trivial, and thus decided against letting pytddmon implicitly run all *.py-code automatically. Of course, test_*.py files are still run implicitly, just as has always been the case for pytddmon.

Leave a Comment

Sharing Buttons by Linksku