Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
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:: ...
jwodder's user avatar
  • 57.3k
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 ...
Migwell's user avatar
  • 20k
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 ...
Martin Thoma's user avatar
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 ...
Jim DeLaHunt's user avatar
  • 11.4k
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 ...
af3ld's user avatar
  • 794
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 ...
orome's user avatar
  • 48.3k
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: '...
Johnny Mann's user avatar
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, ...
alvas's user avatar
  • 122k
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): ''' ...
sphakka's user avatar
  • 496
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 ...
Nikolay Derkach's user avatar
-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 ...
user2987377's user avatar
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....
Mitchell's user avatar
  • 459
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) ...
Jordan Ruatoe's user avatar