Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: resolve doctest issues #555

Merged
merged 2 commits into from
Nov 24, 2023
Merged

Conversation

nathanwn
Copy link
Member

@nathanwn nathanwn commented Nov 14, 2023

While reading through some code, I realized the examples in some docstrings are wrong. These should have been caught by doctest.

Currently in pyproject.toml, pytest is configured as follows:

[tool.pytest.ini_options]
addopts = "--verbose --doctest-modules -ra --cov macaron"  # Consider adding --pdb
testpaths = [
    "tests",
]

Although the --doctest-modules flag is enabled, meaning doctest should run, testpaths is limited to only the tests directory. This does not allow doctest to pick up the docstring examples in src/macaron.

In this PR, I enable doctest to discover docstring examples in src/macaron as follows:

testpaths = [
+   "src/macaron",  # this is included to run doctest on examples
    "tests",
]

I also fix cases where the example fails doctest. There are commonly two reasons why these examples fail:

  • Case 1: The example is wrong. One or more of these things happen: the test is syntactically wrong, or the input is wrong, or the output is wrong. In these cases, I fix the example.
  • Case 2: The example is only intended to demonstrate how the API looks like, and not how it is actually used and what the corresponding result should be. In addition, the setup required for some of these examples is quite complex (e.g. requires loading a config or making an HTTP request). In these cases, I convert the example from using a Python REPL block, which is what doctest picks up, to using a Python code block.

@nathanwn nathanwn self-assigned this Nov 14, 2023
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 14, 2023
Signed-off-by: Nathan Nguyen <[email protected]>
@nathanwn nathanwn force-pushed the nathanwn/resolve-doctest-issues branch from 76613bc to 60777b4 Compare November 14, 2023 01:57
@nathanwn nathanwn marked this pull request as ready for review November 14, 2023 03:32
Copy link
Member

@tromai tromai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for having a look @nathanwn . LGTM.

@nathanwn nathanwn merged commit 2d7ff97 into staging Nov 24, 2023
12 checks passed
@nathanwn nathanwn deleted the nathanwn/resolve-doctest-issues branch November 24, 2023 05:55
art1f1c3R pushed a commit that referenced this pull request Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants