doctest Questions

3

Solved

Is it possible to write a doctest unit test that will check that an exception is raised? For example, if I have a function foo(x) that is supposed to raise an exception if x < 0, how would I wri...
Erv asked 15/8, 2008 at 18:43

3

Solved

In Python (3.3.2) doctest, ellipsis (...) can match any string. So, for the code below def foo(): """ >>> foo() hello ... """ print("hello world") when running doctest it shouldn't...
Aultman asked 13/6, 2013 at 16:24

1

Solved

Example code: async def test(): """ >>> await test() hello world """ print("hello world") Attempting to run this with doctests results in SyntaxError: 'await' outside function.
Artiste asked 18/4, 2020 at 18:53

3

Solved

I am adding unit tests and to a kind of "legacy" Python package. Some of the modules contain their own doctests embedded in docstrings. My goal is to run both those doctests and new, dedicated unit...
Koreykorff asked 13/3, 2018 at 11:16

2

Solved

I have written a small library that uses doctest. In CMakeLists.txt I have: ... add_library(my_lib STATIC ${SRCS} $<TARGET_OBJECTS:common_files>) add_executable(tests ${SRCS} $<TARGET_OB...
Exstipulate asked 17/11, 2019 at 17:36

2

Solved

I have a Python3 function that returns a multi-line string. I want to test it with doctest, but can't get it to work. I've tried using the +NORMALIZE_WHITESPACE directive without success. def dumm...
Pancratium asked 11/10, 2019 at 10:4

2

Solved

I'm using doctest for the tests in my C++ project. I would like to put the test code alongside my implementations, as the library says is possible, but I can't seem to figure out what to do with t...
Expedite asked 18/3, 2019 at 8:1

3

Solved

Is there a way to write a python doctest string to test a script intended to be launched from the command line (terminal) that doesn't pollute the documentation examples with os.popen calls? #!/u...
Griffe asked 2/4, 2012 at 9:26

1

Solved

Suppose I have the following code in foo.py: def start(): """ >>> start() Hello world """ test = 10 print('Hello world') Normally, I would run the doct...
Hexahydrate asked 5/7, 2018 at 13:44

2

Solved

Consider the following demo script: # -*- coding: utf-8 -*- from __future__ import division from __future__ import unicode_literals def myDivi(): """ This is a small demo that just returns the ...
Korella asked 10/2, 2017 at 11:51

3

Solved

In the PyCharm IDE, if I right-click on a function/method with a doctest, sometimes the right-click menu will give me the option: "Run 'Doctest my_function_name'" and sometimes the right-click menu...
Cherri asked 24/3, 2015 at 19:4

3

Solved

I have a sample doctest like this one. """ This is the "iniFileGenerator" module. >>> hintFile = "./tests/unit_test_files/hint.txt" >>> f = iniFileGenerator(hintFile) >>&gt...
Transcription asked 28/10, 2012 at 3:21

1

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...
Aggy asked 28/9, 2017 at 9:17

3

Is there a way to have a doctest with file paths as output that will succeed regardless of the OS it's run on? For example, on Windows this will work: r""" >>> import foo >>> re...
Demibastion asked 12/8, 2014 at 7:27

2

We use pytest to test our project and have enabled --doctest-modules by default to collect all of our doctests from across the project. However there is one wsgi.py which may not be imported durin...
Monaural asked 28/12, 2016 at 9:11

4

Solved

How can I make my (Python 2.7) code aware whether it is running in a doctest? The scenario is as follows: I have a function that print()s some output to a file descriptor passed in as an argument,...
Malposition asked 14/11, 2011 at 0:49

6

Solved

Given the following python script: # dedupe.py import re def dedupe_whitespace(s,spacechars='\t '): """Merge repeated whitespace characters. Example: >>> dedupe_whitespace(r"Green\t\t...
Boson asked 12/1, 2012 at 12:14

3

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: 'mo...
Nygaard asked 17/3, 2015 at 0:10

4

Solved

Is it possible to use Python's doctest concept for classes, not just functions? If so, where shall I put the doctests - at the class' docstring, or at the constructor's docstring? To clarify, I'm...
Babbage asked 25/4, 2010 at 12:24

2

Solved

Python3 test cases (doctests) are failing with my sample code. But the same is working fine in Python2. test.py: class Test(object): def __init__(self, a=0): self.a = a def __getattr__(self, at...
Screenplay asked 14/3, 2018 at 7:7

4

Solved

This code runs fine under regular CPython 3.5: import concurrent.futures def job(text): print(text) with concurrent.futures.ProcessPoolExecutor(1) as pool: pool.submit(job, "hello") But if y...

1

Solved

Pycharm is great for running all of the doctests per (script / function / class / folder*) but the folder option runs all doctests which are immediately within that folder (not within folders of th...
Pajamas asked 25/12, 2017 at 13:30

1

Solved

From Doctest's readme, one can use doctest with QuickCheck, like this: -- | -- prop> sort xs == (sort . sort) (xs :: [Int]) I would like to describe this property using multiple lines, probab...
Fruitful asked 15/6, 2015 at 3:20

2

Solved

I'm using Python 2.7.9 in Windows. I have a UTF-8-encoded python script file with the following contents: # coding=utf-8 def test_func(): u""" >>> test_func() u'☃' """ return u'☃' ...
Duroc asked 16/5, 2015 at 3:19

2

Solved

I'm trying to keep my source code under the 80 character guideline width that PEP8 recommends, but can't figure out how to wrap my doctest which has results longer than 80 characters. A noddy exam...
February asked 15/11, 2012 at 10:30

© 2022 - 2025 — McMap. All rights reserved.