-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #802 from glotzerlab/fix/doctests-pytest
Fix doctests to work with pytest.
- Loading branch information
Showing
5 changed files
with
46 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
import doctest | ||
import inspect | ||
|
||
import pytest | ||
|
||
import freud | ||
|
||
|
||
def load_tests(loader, tests, ignore): | ||
optionflags = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | ||
def fetch_doctests(): | ||
finder = doctest.DocTestFinder() | ||
for name, member in inspect.getmembers(freud): | ||
if inspect.ismodule(member): | ||
tests.addTests(doctest.DocTestSuite(member, optionflags=optionflags)) | ||
return tests | ||
for docstring in finder.find(member): | ||
if docstring.examples: | ||
yield docstring | ||
|
||
|
||
class TestDoctests: | ||
@pytest.mark.parametrize( | ||
"docstring", fetch_doctests(), ids=lambda docstring: docstring.name | ||
) | ||
def test_docstring(self, docstring): | ||
optionflags = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | ||
runner = doctest.DocTestRunner(optionflags=optionflags) | ||
runner.run(docstring) | ||
results = runner.summarize() | ||
if results.failed: | ||
raise AssertionError(results) |