457 questions
1
vote
1
answer
36
views
How to run doc-tests without printing output
I want to run doc-tests and get the number of failures, but not print any output. For example, I tried this:
with open(os.devnull, 'w') as sys.stdout:
tests_failed, tests_run = doctest....
0
votes
0
answers
38
views
How do you pass options to doctest when running 'make doctest' from Sphinx?
We use make html to build HTML docs from .rst docs and our Python code using Sphinx. We have also enabled the sphinx.ext.doctest extension in Sphinx so that we can test any code samples in our docs by ...
4
votes
1
answer
48
views
How to have decorated function in a Python doctest?
How can I include a decorated function inside a Python doctest?
def decorator(func):
def wrapper() -> None:
func()
return wrapper
def foo() -> None:
"""
...
0
votes
1
answer
57
views
Easy to copy Python code snippets with doctest enabled
When adding doctests to my markdown, I have to write something like
```python
>>>import numpy
>>>np.sum([1, 2])
3
```
This works fine with doctest. However, when I render the markdown page on Github,...
4
votes
3
answers
6k
views
How to stop numpy floats being displayed as "np.float64"?
I have a large library with many doctests. All doctests pass on my computer. When I push changes to GitHub, GitHub Actions runs the same tests in Python 3.8, 3.9, 3.10 and 3.11. All tests run ...
0
votes
0
answers
21
views
Is doctest riskier than unittest or pytest because of exec()?
I recently read on Real Python that using doctest is risky because it's based on exec() and therefore you are open to the execution of arbitrary code. The article states that you must be very aware of ...
0
votes
1
answer
81
views
What does 'Got nothing' mean, after running a doctest?
I am making a method to find the largest value in a binary tree and I think I did it right but when i run my doctest on it, it says the expected value but then says 'Got nothing'. I'm not sure what ...
0
votes
0
answers
24
views
How to link doctest with Botan
I am having difficulty in linking Botan with doctest.
I followed the CLion documentation and I have this:
\PROJECT
|____ \cmake
| |____ FindBotan.cmake <== My Botan CMake
| ...
0
votes
0
answers
69
views
In Rust doctest, why can't I use a public static function?
Here is a short example:
//!
//! example:
//!
//!```
//!
//! use nalgebra::{Quaternion, UnitQuaternion, Vector3};
//! // use crate::naive_cf::NaiveCF;
//!
//! let acc = Vector3::new(3....
3
votes
0
answers
42
views
Using doctest with pandas, how to fix the number of columns in the output example?
I have a package with many methods that output pandas data frame.
I would like to test the examples with pytest and doctest as explained on the pytest doctest integration page.
Pytest requires the ...
0
votes
0
answers
33
views
How should I make the code match up to pass doctests?
I implemented a PCA class like this:
import numpy as np
import matplotlib.pyplot as plt
class PCA:
def __init__(self, n_components):
print('****** Created from-scratch PCA object *****')
...
3
votes
2
answers
291
views
How do I get doctest to run with examples in markdown codeblocks for mkdocs?
I'm using mkdocs & mkdocstring to build my documentation and including code examples in the docstrings. I'm also using doctest (via pytest --doctest-modules) to test all those examples.
Option 1 - ...
0
votes
0
answers
89
views
Using doctest with c++, where can I place initialization code?
I'm using doctest with DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
defined so that doctest provides its own main function when I run tests. It's been working great this way but now I need to run some setup ...
0
votes
0
answers
44
views
How to reset doctest in jupyter notebook?
I call doctest.testmod() at the end of some my cell to run tests in my notebook.
But when I rerun this cell doctest raise some exception which forces me to restart all notebook.
Is there some function ...
0
votes
0
answers
12
views
Doctest with an imported dictionary in a function that uses only some key-value paris
I have the following problem: I have a file in which I have a dictionary, that looks like this:
d = {"a": 3, "b": 4, "c": 5, "d": 6, "e": 4}
I ...
0
votes
0
answers
89
views
How do I get access to Python doctest verbose flag inside a test?
How do I get access to Python 3.8 doctest verbose flag inside a test?
I see it as DocTestRunner._verbose but I would need an instance to grab it from.
I'm trying to do something like
def MyClass
&...
0
votes
0
answers
171
views
Unable to open source file "doctest/doctest.h" and "cxxopts.hpp"
I created a repository from the template provided on
https://github.com/TheLartians/ModernCppStarter
I clone the repo and opened it using CLION and visual studio code. I expected that both the ...
5
votes
1
answer
158
views
Doctest of function with random output
I have a function that prints a somewhat random string to the console, for example:
from random import choice
def hello():
print(f"Hello {choice(('Guido', 'Raymond'))}!")
Please note ...
2
votes
1
answer
262
views
Python docstring: inconsistent leading whitespace error without new line
my docstring:
def some_f():
"""
1. First story
>>> str(5)
if you want to see the value:
>>> print(str(5))
2. Another story
...
3
votes
1
answer
553
views
Dedicated main() for doctest.h but with tests also written in production code in C++
I'm under the impression this functionality exists on doctest but I wasn't able to implement it, and I'm not even sure anymore if this is possible.
I already have read a lot of references, but failed ...
0
votes
0
answers
32
views
Automating doctest?
If I were to automate doctest.testmod() how would this occur? It appears testmod runs the tests over the module and provided a string result TestResults. Unsure how to parse this.
def average(values):
...
2
votes
1
answer
103
views
Python doctest dictionary equality test with a strange failure (python bug?)
This test isn't failing appropriately. What is wrong?
This incorrectly passes!?
def drop_keys_conditionally(some_dict):
"""Weird bug where the dictionary equality shouldn't pass but ...
0
votes
1
answer
48
views
Python doctest with abstractmethod
I want to implement a class property that behaves differently based on an abstract class method in Python and have its doctest. But running doctest gives an error that I want to avoid.
Here is a ...
1
vote
0
answers
98
views
How to make sphinx-apidoc, doctest and -W option play together nicely?
My current pipeline looks something like the following:
sphinx-build -b doctest -d docs/build/doctrees docs docs/build/doctest
sphinx-apidoc -f -o docs/ src/my_package
sphinx-build -b html -d docs/...
0
votes
0
answers
108
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 >&...
0
votes
1
answer
587
views
Importing module from parent directory in python interactive mode
I'm trying to import and run a module from a parent directory in python interactive mode.
My directory looks like this:
modules:
tests:
So, I'm trying to import the modules in the modules ...
1
vote
1
answer
103
views
Unexpected Doctest result for an output including a backslash [duplicate]
This doctest fails with an output shown at the bottom. Why does Pytest change the doctest to strip_special_chars( "c:\abcDEF1 [email protected]") with a single backslash leading to the unintended ...
-2
votes
1
answer
85
views
Module doctest does not run [closed]
I am trying to use the doctest module to test code. I tried this example:
import doctest
def areaTriangulo(base, altura):
return 'El area del triangulo es: '+str((base*altura)/2)
""...
1
vote
1
answer
1k
views
Apache Airflow | Testing
I am new to Apache airflow and have been assigned a task to determine frameworks which can be used to unit and integration testing of Airflow DAGs. Until now I have seen examples of pytest and Python ...
0
votes
0
answers
54
views
how can i write unittest for my argparser?
This is my argparse command line interface which use to options --filter and --count.
i'm (filtering/count) a data.json file, which i convert to list python.
My question is how do I write tests for ...
1
vote
0
answers
91
views
Why do module doctests stop working when there are module variables?
Take the following example. Why does uncommenting that line on the top cause the doctest to stop working?
#a = 3 # Uncommenting this line causes the doctest to stop working
"""
>&...
0
votes
2
answers
78
views
How do I add bytearrays to doctests?
This is my function signature,
def fun12(bytes_var: bytearray, signed: bool) -> (int):
When I do,
print(fun12(b'\x00\x10',False))
My code works just fine, but when I have something like the ...
2
votes
0
answers
43
views
How to test `pickle`-ability in a `doctest`?
My actual application is that I'm trying to demo/test the "pickability" of some objects in a doctest, but doctest and pickle don't seem to play along well (in general, actually). Below is ...
0
votes
1
answer
126
views
Define a dataclass in a doctest body [duplicate]
I need to define a temporary dataclass in order to test a given function via Doctest.
However, I am not able to use to @dataclass decorator syntax in a doctest body.
Sample file test.py:
from typing ...
1
vote
2
answers
1k
views
pytest markers are not working when running doctest with pytest runner
Trying to run doctest tests using pytest runner and wanted to use markers functionality to group them and run selectively.
Whole module where doctests are declared is marked as following:
pytestmark = ...
0
votes
0
answers
42
views
How may I execute the doctest I'm seeing under pycharm?
I bought a book to learn Python, and downloaded its sources from here.
It's first chapter shows me this structure, under PyCharm :
If I can run frenchdeck.py, which displays nothing for itself : it's ...
0
votes
0
answers
158
views
Doctest and qapplication
I must integrate doctest lib to a QT core project (Qt5 exactly).
At a point, I need a qcoreapplication to run event loop.
But when I try implement my doctest main with a qcoreapplication it looks ...
1
vote
1
answer
439
views
Doctest not working in Sphinx, cannot import python files Python
I have a problem trying to run doctest from the Sphinx Tutorial. I have the directory tree below but I cannot run a doctest for lumache.py. How would be able to make it so that lumache.py is ...
0
votes
1
answer
376
views
How can I have a doctest test that the result includes some text, rather than an exact match?
I understand that I can write a doctest like:
def foo():
"""
>>> foo()
'abc'
"""
return 'abc'
However, what if my function is fetching a ...
1
vote
1
answer
492
views
How to test a single docstring using pytest --doctest-modules?
I know that a single test using pytest can be achieved using pytest test.py::test_single. Is there a similar method for choosing a single docstring test to run using pytest --doctest-modules mymodule....
0
votes
0
answers
36
views
Python doctest - example failure - need answers
def check_TLA(w1, w2, w3):
'''
>>> check_TLA("Game" , "of", "thrones")
'GOT'
>>> check_TLA("impressive", "optical", "under"...
0
votes
1
answer
1k
views
Pytest run tests and doctests with coverage
I want to run pytest with coverage (pytest-cov) for my set of tests (stored in ./test) + doctests (stored in ./myproj/*.py) in a single command but I seem to be unable to get it to work
Running the ...
1
vote
1
answer
433
views
Doctest doesen't give output
My problem is that whenever I use doctest I receive no errors, no exceptions and no output at all. I checked if my file has ".py" extension, I tried running it through command line (in case ...
1
vote
3
answers
552
views
Python doctest: have a common initialization for several tests
I want to have a doctest for a class, where the use of the class needs a somehow lengthy setup. Like:
class MyClass
def __init__(self, foo):
self.foo = foo
def bar(self):
&...
1
vote
1
answer
800
views
Unable to compile doctest's `CHECK_THROWS_AS` with Visual Studio 2019
Consider the following code using doctest.h C++ unit test library:
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
TEST_CASE("") {
CHECK_THROWS_AS(throw 0, int);...
1
vote
1
answer
36
views
Doctest letter extraction
Extract all the unique letters present in the text string.
:param text: string data
:return: a tuple of all the unique letters of the string in lowercase
def extract_letters(text):
""&...
0
votes
0
answers
399
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 ...
2
votes
1
answer
207
views
Can I modify doctest to test bash inside sphinx doc?
My original question was "can I doctest bash"?
I've found a few similar questions, and the answers are pretty much:
Use subprocess
No
Use other module (docshtest was the best I could find)
...
2
votes
0
answers
19k
views
Why I'm getting "UnicodeEncodeError: charmap' codec can't encode characters in position 24-25: character maps to <undefined>? [duplicate]
When I ran the Doctests with Coverage in PyCharm, I got the following error:
Testing started at 12:25 AM ...
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2021.3.1\...
2
votes
0
answers
197
views
Way to exclude directories when running make doctest
I have a python library which uses Sphinx to build documentation pages. The library structure is as follows:
Library-name
|- /docs
| |- <lots of .rst files>
| |- config.py
|
|- /src
| |- <...