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

ENH: make collection strategy user configurable in the pytest layer #128

Merged
merged 2 commits into from
Feb 28, 2024

Conversation

ev-br
Copy link
Member

@ev-br ev-br commented Feb 27, 2024

This is a breaking change: the default collection strategy changes from "api" to vanilla pytest.

Add a cmdline option, --doctest-collect={None, api}

The default is now the vanilla doctest collection, strategy=None. To select strategy='api', use the command flag

$ pytest --doctest-modules --doctest-collect=api

When to use what. strategy='api' is meant for packages with non-trivial internal structure and where you only enfore doctests correctness for public objects.

For individual single-file modules, you probably want strategy=None.

closes gh-114

P.S. I manually checked

<Dir scipy>
  <Dir build-install>
    <Dir lib>
      <Dir python3.10>
        <Dir site-packages>
          <Package scipy>
            <Package linalg>
              <DTModule _basic.py>
                <DoctestItem scipy.linalg._basic.det>
                <DoctestItem scipy.linalg._basic.inv>
                <DoctestItem scipy.linalg._basic.lstsq>
                <DoctestItem scipy.linalg._basic.matmul_toeplitz>
                <DoctestItem scipy.linalg._basic.matrix_balance>
                <DoctestItem scipy.linalg._basic.pinv>
                <DoctestItem scipy.linalg._basic.pinvh>
                <DoctestItem scipy.linalg._basic.solve>
                <DoctestItem scipy.linalg._basic.solve_banded>
                <DoctestItem scipy.linalg._basic.solve_circulant>
                <DoctestItem scipy.linalg._basic.solve_toeplitz>
                <DoctestItem scipy.linalg._basic.solve_triangular>
                <DoctestItem scipy.linalg._basic.solveh_banded>
  • We can specify individual functions to doctest: $ python dev.py test --doctests -t scipy/linalg/_basic.py::scipy.linalg._basic.det -v -- --collect-only produces
<Dir scipy>
  <Dir build-install>
    <Dir lib>
      <Dir python3.10>
        <Dir site-packages>
          <Package scipy>
            <Package linalg>
              <DTModule _basic.py>
                <DoctestItem scipy.linalg._basic.det>

Note the need to specify the full dotted name of the doctested object.

The default is the vanilla doctest collection, strategy=None.
To select strategy='api', use the command flag

$ pytest --doctest-modules --doctest-collect=api

When to use what. strategy='api' is meant for packages with
non-trivial internal structure and where you only enfore doctests
correctness for public objects.

For individual single-file modules, you probably want strategy=None.
@ev-br ev-br added enhancement New features w.r.t. the original refguide-check pytest-plugin labels Feb 27, 2024
@ev-br
Copy link
Member Author

ev-br commented Feb 28, 2024

@Sheila-nk WDYT?

@ev-br
Copy link
Member Author

ev-br commented Feb 28, 2024

Note to self: remember to update scipy/scipy#20127 when this lands.

@Sheila-nk
Copy link
Collaborator

I think it's great you made the collection strategy configurable. Looks good to me! 🚀

@ev-br ev-br merged commit 9d7bc5b into main Feb 28, 2024
4 checks passed
@ev-br ev-br deleted the addoption_t branch February 28, 2024 18:30
@ev-br
Copy link
Member Author

ev-br commented Feb 28, 2024

Let's roll with it then. More tweaks are on the way based on the combination of this and gh-133. Thanks Sheila.

@ev-br
Copy link
Member Author

ev-br commented Feb 28, 2024

Did not mean to squash-merge. Not a big deal though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features w.r.t. the original refguide-check pytest-plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make collection strategy={None, "api"} selectable when run via pytest
2 participants