All Questions
Tagged with doctest python-2.7
13 questions
1
vote
1
answer
469
views
pytest can't handle Unicode in doctest in README under Python 2.7
I have a README.rst file containing several doctests for my Python library. They all work, except for the last doctest, which prints Unicode output, encoded in UTF-8:
Here is a failing example::
...
2
votes
1
answer
474
views
Recursively loading doctests in python
I'm trying to test a python module, which has a separate test module:
my_module/
test/
setup.py
The test module has unittests for my_module, but it also needs to load doctests from my_module. To ...
3
votes
1
answer
251
views
How can I make doctests triggered by pytest ignore unicode prefix `u'...'` of strings?
I want my code to work in Python 2 and 3. I use doctests and
from __future__ import unicode_literals
Is there a flag I can set / a plugin which makes it ignore that Python 2 has the u prefix for ...
3
votes
2
answers
1k
views
Why is importing a module breaking my doctest (Python 2.7)
I tried to use a StringIO instance in a doctest in my class, in a Python 2.7 program. Instead of getting any output from the test, I get a response, "Got nothing".
This simplified test case ...
6
votes
1
answer
188
views
Python: accept unicode strings as regular strings in doctests
Writing doctests for a method that abbreviates a dictionary by searching for a passed key word in the keys of the original dictionary, and returning the new, abbreviated dictionary. My docstring looks ...
1
vote
1
answer
470
views
How can I test output of non-ASCII characters using Sphinx doctest?
I'm at a loss how to test printing output that includes non-ASCII characters using Sphinx doctest.
When I have test that include code that generates non-ASCII characters, or that contains expected ...
9
votes
3
answers
5k
views
AttributeError: 'module' object has no attribute 'testmod' Python doctest
When ever I try to doctest in python, basically whenever I run the code
if __name__ =="__main__":
import doctest
doctest.testmod()
I get this response from the interpreter
AttributeError: '...
0
votes
0
answers
19
views
Checking doctest for both Python 2 and Python 3 [duplicate]
Python 2 and Python 3 giving the same dict in different order and different encoding.
From the code: https://github.com/alvations/nltk/blob/develop/nltk/translate/util.py
And running the code, ...
5
votes
1
answer
419
views
python-2.7: doctests ignored in setter method of a class
Why does the following example fail to run its doctest in the setter method?
class Foo:
a = None
@property
def a(self):
pass
@a.setter
def a(self, v):
'''
...
10
votes
1
answer
877
views
Python doctest exceptions
So, I'm trying to match an exception with a doctest.
>>> api = Api("foo", "bar") # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
AuthError
The issue is that this ...
-1
votes
3
answers
748
views
Failed test - python palindrome checker
I have created a very simple palindrome checker with doctests.
I'm having problem with the last doctest. It fails and is not carrying out the ignorecase=True. I cannot work out why the last test is ...
2
votes
1
answer
796
views
Doctest with datetime
I have done a search but could not find what I was after.
My code is as followed:
import datetime
import doctest
import os
def parseOptions():
import optparse
parser = optparse....
2
votes
1
answer
23k
views
How do I write a compare function? [closed]
def compare(a, b):
"""
Return 1 if a > b, 0 if a equals b, and -1 if a < b
>>> compare (5, 7)
1
>>> compare (7, 7)
0
>>> compare (2, 3)
...