doctest

Unit testing infrastructure for a python module

Hi there, I'm writing a python module and I would like to unit test it. I am new to python and somewhat bamboozled by the options available. Currently, I would like to write my tests as doctests as I like the declarative rather than imperative style (however, feel free to disabuse me of this preference if it is misinformed). This rai...

Running a MATLAB code fragment without namespace pollution

Hi! I'm writing a version of Python's doctest test-runner, for MATLAB (it partly works...). For this to work, I need to run the code in people's examples in their m-file help. I want variables to carry over from one line to the next, e.g. % >> I = 5 + 33; % expect no output % >> I % % I = % % 38 % To run the tests, I have a l...

Embedding test code or data within doctest strings

I'd like to have several of the doctests in a file share test data and/or functions. Is there a way to do this without locating them in an external file or within the code of the file being tested? update """This is the docstring for the module ``fish``. I've discovered that I can access the module under test from within the doctes...

PyDev Question: Setting breakpoints in doctests

Is it possible to set breakpoints in doctests, using PyDev (i.e. eclipse)? I found that while I am seemingly able to do so, the breakpoints do not work at all. To have some code in the question, and to clarify, say I have def funct(): """ >>> funct() Whatever """ print "Whatever" and that I set a breakpoint at the funct() ...

Python using doctest on the mainline

Hello i was wondering if it is possible and if so how? to do doctests or something similar from the mainline, instead of testing a function as is described in the doctest docs i.e. """ >>> Hello World """ if __name__ == "__main__": print "Hello" import doctest doctest.testmod() This is part of being able to test students...

Run all my doctests for all python modules in a folder without seeing failures because of bad imports

I've started integrating doctests into my modules. (Hooray!) These tend to be files which started as scripts, and are now are a few functions with CLI apps in the __name__=='__main__', so I don't want to put the running of the tests there. I tried nosetests --with-doctest, but get lots of failures I don't want to see, because some of ...

python doctest: stop example execution and use the resulting context in some shell

i think there was some directive i could enter in the test that would allow me to run some commands interactively at the point of the directive and then continue the example, but i dont remember what it was... ...

Can modipyd run Doctests?

When doing quick scripts I like to use DocTests to make things a bit quicker, recently I saw someone using autospec at a recent DevCon I attended when they were introducing us to the concept of CodeKata. I spent the train ride home looking for a Python equivalent of Autospec & found modipyd, but I'm struggling to get it to run my doctes...

Python doctest example failure

This is probably a silly question. I am experimenting with python doctest, and I try to run this example ending with if __name__ == "__main__": import doctest doctest.testfile("example.txt") I have put "example.txt" in the same folder as the source file containing the example code, but I get the following error: Traceback (...

Doctests: How to suppress/ignore output?

The doctest of the following (nonsense) Python module fails: """ >>> L = [] >>> if True: ... append_to(L) # XXX >>> L [1] """ def append_to(L): L.append(1) class A(object): pass return A() import doctest; doctest.testmod() This is because the output after the line marked XXX is <__main__.A object at ...> (whic...

How come there's no C# equivalent of python's doctest feature?

Seems like it would be a good way to introduce some people to unit testing. ...

Doctest and relative imports

I'm having trouble using doctest with relative imports. The simple solution is just to get rid of the relative imports. Are there any others? Say I have a package called example containing 2 files: example/__init__.py """ This package is entirely useless. >>> arnold = Aardvark() >>> arnold.talk() I am an aardvark. """ from .A impor...