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

Figure out implementation of doctest for testing #23

Closed
caldwellst opened this issue Nov 3, 2021 · 3 comments
Closed

Figure out implementation of doctest for testing #23

caldwellst opened this issue Nov 3, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request with main implementation details already defined

Comments

@caldwellst
Copy link
Contributor

The Python native doctest module allows the use of docstring examples as tests, to reduce the need to duplicate writing unit tests (and encourage good example documentation). However, when initially testing the implementation of this, test coverage was dramatically increasing, even for functions without doctests in their docstring.

We need to sort out this issue before we can implement doctests. I attempted to generate a response on SO and in #504 in the pytest-cov repository. When the issue is sorted later down the line, we can easily activate this functionality in the pa-aa-toolbox by adding the following lines to the setup.cfg:

[tool:pytest]
addopts = --doctest-modules
@caldwellst caldwellst added the enhancement New feature or request with main implementation details already defined label Nov 3, 2021
@caldwellst caldwellst mentioned this issue Nov 3, 2021
@caldwellst
Copy link
Contributor Author

So, reading through the doctest documentation, I decided that I would instead try adding in doctest to unittest discovery, which has now worked as intended, although I would consider that coverage is relatively low still (will need to investigate further). In this method, we explicitly created a function to find and run all doctest examples from a specific module. For the raster module, the code looks like below:

import unittest
import doctest
from aatoolbox.utils import raster

def load_tests(loader, tests, ignore):
    tests.addTests(doctest.DocTestSuite(raster))
    return tests

This is pulled straight from the doctest documentation.

@turnerm
Copy link
Member

turnerm commented Nov 11, 2022

@caldwellst has this been addressed to your satisfaction?

@caldwellst
Copy link
Contributor Author

Ha, yes, sorry, lots of outstanding issues I see you're cleaning. Has worked great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request with main implementation details already defined
Projects
None yet
Development

No branches or pull requests

2 participants