Test docs code snippets with pytest doctests#362
Test docs code snippets with pytest doctests#362kataev wants to merge 1 commit intozzzeek:masterfrom kataev:pytest-doctests
Conversation
|
OK, you may be aware that we do use doctests for our two tutorials at http://docs.sqlalchemy.org/en/latest/orm/tutorial.html and http://docs.sqlalchemy.org/en/latest/core/tutorial.html. The doctests for these are also integrated within our test suite. These are not using the py.test integration points, however, and I'm not familiar with what additional behaviors the py.test points bring. My comments below are based on what I know about doctest. I am uncomfortable using doctest for 100% of .rst files for the following reasons:
Above, this is not acceptable for doctest. It must instead be: The reader is now confused. Does "in_()" only work with Integer? Is this Column part of a Table ? E.g., doctest requires that our example must have a lot more than just the thing being demonstrated itself, leading to confusion as to which part of the code is the thing that's being illustrated, and which parts are just to satisfy doctest.
Overall, the main reason I dont think "doctest everywhere" is viable for SQLAlchemy comes down to level of effort and ongoing maintenance burden in conjunction with the specific nature of doctest (e.g., the idea is good but in practice it needs to be more flexible). I do 95% of the work on SQLAlchemy myself and I simply do not have the time to maintain thousands of doctest code examples and to also have these requirements when writing new code. They don't make the documentation clearer, lead to confusion as to what's being illustrated and what's just boilerplate, new documentation becomes much more time consuming to write; documentation is already by far the most time consuming thing I have to deal with. That said, if there was some alternate form of "doctest" that could simply test a code example both for Python syntax, pep8 compliance (which would be AWESOME) as well as symbol consistency, that would be helpful. The tool could be configured with common imports and symbols significant to SQLAlchemy examples and be helpful as a basic sanity check for code examples. As it is, when writing new documentation I have to organize and run the code in a separate .py file to make sure it does the right thing. So this is a problem, just my experience with doctest in writing the tutorials has shown me what it's good at and where it's likely getting in the way. |
|
Thank you for detailed description your position, i am fully agree with your reasoning. I am try to research something for your proposed syntax checks and pep8. |
I propose integrate doctest with documentations code snippets using py.test doctest.
This should helps maintains code snippets up to date.
This is have one aesthetic issue, snippets will have ... and >>> prefix.
i rewrited a random file in documentation for presentation idea.
How to run doctests: