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...
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...
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...
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() ...
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...
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 ...
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...
...
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...
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 (...
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...
Seems like it would be a good way to introduce some people to unit testing.
...
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...