0 votes
in Python by
What is  Docttest?

1 Answer

0 votes
by

doctest is a python testing module, which allows writing tests based on expected output from standard python interpreter along with documentation.

doctest is also known as "document testing" or "testable document".

doctest allows combination of tests and documentation. This feature enables to keep documentation up to date with reality and ensures that tests express the expected behaviour.

A doctest specifications

A doctest contains documentation and one or more valid python statements.

The statements are written after the python shell's primary prompt(>>>).

Secondary prompt (...) is used from second line on wards, when a statement is written across multiple lines.

Expected output is written below the python statements and it should be same as the result obtained, when you run the statement in a python shell.

Writing Tests as Text Documentation

Tests are written in the form of documentation in a text file.

Let's consider the following text in a file named sample_tests.txt. The file contains text documentation and two tests written for testing python's plus operator.

Related questions

+1 vote
asked Jul 16, 2020 in Python by GeorgeBell
+1 vote
asked Jul 16, 2020 in Python by GeorgeBell
...