Use doctest to execute examples in the docstring
See original GitHub issue📚 Documentation
Example snippets are inserted into the docstring to show usage. However, these pieces of code might be deprecated, or might not work. The module doctest
aims to execute the tests written in docstring and it works fine with sphinx. It could help to detect earlier doc issues and provide a better doc.
Useful links
- https://docs.python.org/3/library/doctest.html
- https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html
Note that some tests was written according to doctest
https://github.com/pytorch/ignite/blob/b3d9849c2243be6068a64b5d1cf9c0ede727a2ea/ignite/handlers/timing.py#L30
The main point is the refactoring of every test to pass the validation. It means have consistent pieces of code (define training fn, engines, etc.) to provide reproducible examples.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
doctest — Test interactive Python examples — Python 3.11.1 ...
This section examines in detail how doctest works: which docstrings it looks at, how it finds interactive examples, what execution context it uses,...
Read more >Python's doctest: Document and Test Your Code at Once
The doctest module is able to run code that creates and imports objects, calls functions, assigns variables, evaluates expressions, and more.
Read more >How To Write Doctests in Python - DigitalOcean
Our complete example code, including the add() function with a doctest, docstrings, and a call to invoke the doctest follows.
Read more >doctest – Testing through documentation - PyMOTW
You can include instructions to run doctest against your source at the bottom of your modules. Use testmod() without any arguments to test...
Read more >Testing in Python using doctest module - GeeksforGeeks
1. import testmod from doctest to test the function. 2. Define our test function. 3. Provide a suitable docstring containing desired output on ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s done !
@sdesrozis can we close this issue as solved or still there is something to be done ?