Answer the question
In order to leave comments, you need to log in
How does doctest run test cases?
Created a module doc-tests_launcher.py in the parent directory of the project. It imports test cases with documentation for functions, in which local Python sessions are scheduled.
I assumed that the doctest.testmod() command would also test imported functions.
But the output is:
> python doc-tests_launcher.py -v
Trying:
1
Expecting:
1
ok
1 items had no tests:
__main__
1 items passed all tests:
1 tests in __main__.test_this
1 tests in 2 items.
1 passed and 0 failed.
test passed.
Those. please tell me how to make doctest test imported functions with tests previously written in the documentation for them.
doc-tests_launcher.py:
if __name__ == '__main__':
try:
# Импортирование тест-кейсов.
from tests.doc_string_test_ import *
import doctest
print(dir()) # ['Room', '__annotations__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'doctest', 'test_please]
except Exception as e:
print(e)
def test_this():
"""
>>> 1
1
"""
doctest.testmod()
# Запуск тестов через лаунчер
if __name__ == 'tests.doc_string_test_':
try:
from modules.game import Room
import doctest
except Exception as e:
print(e)
def test_please():
"""
>>> 2
2
"""
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question