Skip to main content

All Questions

Tagged with
0 votes
0 answers
80 views

Python Doctest Syntax requiring blanks after? blanks already included

I am trying to run a Doctest which is returning the following Syntax related error when running Python -m doctest ValueError: line 4 of the docstring for app.check_valid_curr lacks blank after >&...
Sean.realitytester's user avatar
0 votes
0 answers
351 views

doctest not returning a result

I have looked at this question, and have seen this tutorial, but still haven't been able to figure out what is going wrong. I have the following code, just to try out doctest: import doctest def ...
Elise's user avatar
  • 131
1 vote
1 answer
559 views

Doctest multiple files from one file

Project Structure components/ A.py B.py run_test.py A.py and B.py each has some functions with doctest test cases. How can I run all tests in A.py and B.py by running only run_test.py? Any ...
Inyoung Kim 김인영's user avatar
0 votes
0 answers
19 views

Testing a "very close number" in Python with doctest [duplicate]

I'm creating tests for a class using doctest. One of its functions has a random component so its output can vary. I have tried using random.seed() but it changes when I run the file again. I have ...
Aleharu's user avatar
  • 162
2 votes
2 answers
83 views

Doctest: how to not count a setup line as a test?

import doctest __test__['test'] = \ """ >>> y = 1 >>> y == 1 True """ Expected: 0 failed, 1 attempted Actual: 0 failed, 2 attempted How do I tell ...
Ilya's user avatar
  • 516
0 votes
0 answers
20 views

Best suited doc-tests for the verification of the correctness of a function

I was wondering if there is a way to determine the necessary doc-tests for a function? Perhaps a protocol that we need to follow to come up with them? The doc-tests that I could come up with are as ...
Flavio Esposito's user avatar
1 vote
1 answer
327 views

Running Python's doctest on a file named `types.py`

In both Python 2 and 3 I cannot run doctests in a file named types.py, which is part of a package. This is what I get: $ cat foo/types.py def x(): """do something >>> x() 1 "...
Boldewyn's user avatar
  • 82.3k
8 votes
3 answers
3k views

How to let pytest discover and run doctests in installed modules?

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 ...
Cong Ma's user avatar
  • 11.1k
1 vote
0 answers
181 views

How to check output starting with ellipsis in Python's doctests

I have a method which outputs ......silence...... to represent no activity: def silence(self): print('......silence......') I have the following doctest written for the method: >>> s =...
Sam Chats's user avatar
  • 2,291
0 votes
1 answer
54 views

Python - Testing function without doctest

I am currently writing two functions that reverse a string. I already have both of these functions written. Now I'm trying to write a function that has a series of test cases that can be used to test ...
user2951723's user avatar
4 votes
1 answer
1k views

how to automatically change to pytest temporary directory for all doctests

I would like to change to pytest temporary directory at the beginning of each doctest and I was wondering if there is a way to do it automatically without starting every doctests with: >>> ...
d_j's user avatar
  • 1,169
3 votes
2 answers
2k views

How to make python's coverage library include doctests

From googling and experimentation, it seems python's coverage library doesn't include doctests in its calculations. Is there any way to make it do so? I have searched the docs (https://coverage....
Katie Byers's user avatar
0 votes
1 answer
37 views

doctest for extracting seconds

I have a doctest written: def extract_second(triples): """Given a list of triples, return a list with the second element of each triple If an item is not a triple, return None for that element &...
baked182's user avatar
12 votes
0 answers
3k views

Using Mocks inside Doctests?

I am using doctests. I am wondering what is the correct way to doctest a function that performs an external action (e.g. sends email, connects to a server, etc)? Using Mock seems like the answer but ...
m3ta's user avatar
  • 301
5 votes
2 answers
372 views

Doctest fails when normal output and exception mixed together?

Does doctest support that both output and exception mixed together? One example is: >>> def foo(): ... print 'hello world!' >>> foo() hello world! >>> def bar(): ... ...
Congbin Guo's user avatar
  • 1,685

15 30 50 per page