Skip to content

Question is it possible to use the doctest_requires syntax in a python docsrtring similar to SKIP or REMOTE data #279

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

Open
samaloney opened this issue Jan 22, 2025 · 5 comments
Labels

Comments

@samaloney
Copy link

E.g something like this? I've tried everything obvious to me but ...

class MyClass:
     """
     stuff
     
     Examples
     --------
     >>> import numpy as np
     >>> array = np.array([1])
     >>> array # doctest: requires numpy>2.0
     1.0

Use case is where libs change string representations and testing against multiple versions. Currently doing it via pytest config but would be nice to allow per statement

doctest_subpackage_requires =
    * =  numpy>2.0
@pllim pllim added the question label Jan 22, 2025
@pllim
Copy link
Contributor

pllim commented Jan 22, 2025

Would something like this work for you?

https://github.com/astropy/astropy/blob/1382c72878b0389b744348858f797c1be3c9dd21/astropy/stats/jackknife.py#L18

@samaloney
Copy link
Author

Yea that works, not quite as nice though.

@pllim
Copy link
Contributor

pllim commented Jan 23, 2025

I don't see how # doctest: requires numpy>2.0 could be better because that means you have to keep applying that to all the following lines that would depend on that line.

@bsipocz
Copy link
Member

bsipocz commented Jan 23, 2025

I would review such a PR, but very likely won't have time to implement it myself as it has a very narrow use case especially as we're coming close to the recommended drop date of <2.0 numpy (See: https://scientific-python.org/specs/spec-0000/#support-window)

@samaloney
Copy link
Author

It's just something different I, other users, need to remember as I'm used adding +SKIP and +REMOTE inline and was the first thing I thought to try. I think this issue can probably be close now anyway, need to read the docs more carefully, thanks the help. This specific request was for NDCube 2.3.0 as the default repr changed numpy as just another more common example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants