doctest Questions
5
Solved
Does anyone know of an open-source project or program for running tests against code examples in README.md?
A perennial problem, my documentation tends to drift out of date with the code. For exam...
3
Solved
In my test code, my doctest fails but the script exits with a zero return value, which causes the CI run to pass, which is not intended.
Is this the correct behavior of doctest module?
My script ...
8
Solved
I'm writing a doctest for a function that outputs a dictionary. The doctest looks like
>>> my_function()
{'this': 'is', 'a': 'dictionary'}
When I run it, it fails with
Expected:
{'thi...
Jasper asked 21/3, 2013 at 13:51
7
Solved
I'd like to write a doctest like this:
"""
>>> print a.string()
foo : a
bar : b
date : <I don't care about the date output>
baz : c
"""
Is there any way to do this? I think it...
4
Solved
I'd like to run the doctests from this file, and it's not clear to me out to accomplish it:
README.md:
# WELCOME!
This library is helpful and will help you in _many_ ways!
For example:
```
>&...
Datolite asked 23/4, 2014 at 16:21
1
We're using pytest and python std logging, and have some tests in doctests. We'd like to enable log_cli to make debugging tests in ide easier (lets stderr flow to the "live" console so on...
Oleate asked 22/3, 2021 at 23:27
2
I have a Python module for which I'm writing a tutorial using Sphinx including doctests.
This module comes with a few helper programs.
I would like to include those helper programs in the docum...
Ana asked 3/4, 2014 at 16:24
4
Solved
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...
6
Solved
I am using doctest.testmod() to do some basic testing. I have a function that returns a long string, say get_string(). Something like:
def get_string(a, b):
r''' (a, b) -> c
>>> get...
3
I am writing a short tutorial, and would like to be able to run the examples therein using python's doctest using
python -m doctest foo.txt
There is a point in the tutorial at which I want to star...
6
Solved
I've got a Python module with docstrings in class methods, and a real-world example in the module docstring. The distinction is that the method-docstrings have been carefully crafted to be utterly ...
7
Solved
I am currently writing a small application with Python (3.1), and like a good little boy, I am doctesting as I go. However, I've come across a method that I can't seem to doctest. It contains an in...
Eisteddfod asked 1/5, 2010 at 1:49
5
Solved
We currently have pytest with the coverage plugin running over our tests in a tests directory.
What's the simplest way to also run doctests extracted from our main code? --doctest-modules doesn't ...
2
I have a function that uses typing.get_type_hints. I want to add a documentation test to it. However, it looks like get_type_hints fails to resolve types that are defined in a doctest.
Here is a s...
3
Solved
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(ob...
2
Solved
I am trying to get into testing in Python using the doctest module. At the moment I do
Write the tests for the functions.
implement the functions code.
If Tests pass, write more tests and more co...
4
Solved
The following doctest fails:
import logging
logging.basicConfig(level=logging.DEBUG,format='%(message)s')
def say_hello():
'''
>>> say_hello()
Hello!
'''
logging.info('Hello!')
if ...
2
I know how to skip a doctest using # doctest: +SKIP, but I can't figure out how to skip a test sometimes, based on a runtime condition. For example:
>>> if os.path.isfile("foo"):
... open...
3
Solved
I think I am missing something about the sphinx extension for doctest.
The typical example in the documentation is:
.. doctest::
>>> print 1
1
Isn't there a way to let sphinx genera...
Landgrave asked 21/3, 2012 at 17:6
3
Solved
I can't get a doctest to work with a result which contains multiple lines and may contain empty lines at the beginning. This is probably caused by indentation and parsing issues. I've figured out s...
0
The Sphinx extension sphinx.ext.doctest makes it straightforward to ensure that your documentation is up to date. At the same time, the matplotlib.sphinxext.plot_directive extension makes it straig...
Overstudy asked 30/6, 2021 at 17:26
7
Solved
I'd like to use doctests to test the presence of certain warnings. For example, suppose I have the following module:
from warnings import warn
class Foo(object):
"""
Instantiating Foo always gi...
5
Solved
Python doctests are cool. Let me start with a simple example:
def foo():
"""
>>> foo()
hello world
"""
print "hello world"
Now let's assume some part is somewhat varying, e.g., bec...
3
Solved
Using Python 2.7 I'm trying to test that the result of a particular function call is None
I would expect these tests to pass (excuse the rather silly example)
def six_or_none(val):
"""
>>...
4
Solved
There seems to be a package to enable this functionality, but I have no luck with it in python 3.5.2, or 2.7.12:
from ipython_doctester import test
@test
def my_fun():
'''
>>> 2 + 3
6...
Cirro asked 19/10, 2016 at 17:30
1 Next >
© 2022 - 2024 — McMap. All rights reserved.