Skip doctest collection in subpackages based on requirements#112
Skip doctest collection in subpackages based on requirements#112pllim merged 8 commits intoscientific-python:masterfrom
Conversation
pllim
left a comment
There was a problem hiding this comment.
Thanks. Conceptually, this is awesome!
However, I think we should open an experimental PR over at astropy to test this out in practice before merging, if the other reviewers are okay with this PR.
| c.join('testcode.py').write(pyfile) | ||
|
|
||
| reprec = testdir.inline_run(test, "--doctest-plus") | ||
| reprec.assertoutcome(passed=1) |
There was a problem hiding this comment.
Is there a way to check that the one passed is actually "a"?
README.rst
Outdated
| >>> asdf.open('file.asdf') | ||
|
|
||
| Finally, it is possible to skip collecting doctests in entire subpackages by | ||
| using the ``doctest_subpackage_requires`` option in ``pytest.ini`` or |
There was a problem hiding this comment.
What about tox.ini? I think that is one of the 3 files that pytest will look for; see https://docs.pytest.org/en/latest/customize.html#finding-the-rootdir
There was a problem hiding this comment.
In fact elsewhere in the README we only mention setup.cfg so I've updated it to match other parts of the README.
Will do! |
|
@pllim - what do you find more readable: or (that is, : or = as a separator?) |
|
I think the |
|
Ok I'll change it once I know if astropy/astropy#10358 works |
|
Not sure why _check_distribution emitted a warning but I don't think it's needed, so removing that. |
pytest_doctestplus/plugin.py
Outdated
|
|
||
| parser.addini("doctest_subpackage_requires", | ||
| "A list of paths to skip if requirements are not satisfied. Each item in the list " | ||
| "should have the syntax path:req1;req2.", |
pllim
left a comment
There was a problem hiding this comment.
I am excited! Some minor comments.
| break | ||
|
|
||
| for option in config.getini("doctest_subpackage_requires"): | ||
| subpackage_pattern, required = option.split('=', 1) |
There was a problem hiding this comment.
Will adding spaces around = affect the logic here?
There was a problem hiding this comment.
Yep it works! But I added calls to strip() in my latest commit to make really sure.
Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
pllim
left a comment
There was a problem hiding this comment.
LGTM. Definitely a great improvement. Thanks!
This implements an idea related to those in #110, namely that we can skip collecting doctests in specific sub-packages by specifying paths and requirements in the
setup.cfgfile, e.g.:This ended up being cleaner than using e.g.
__doctest_subpackage_requires__in e.g.__init__.pyfiles since these would need to be parsed with e.g. ast and not imported and so on.Note that for skipping
setup_package.pyfiles there is already a solution which is to specify:in
setup.cfgfiles and it works nicely.Note that this then adds back the default behavior of failing on import errors since there is now a way to work around those.
EDIT: Fix #110