Skip to content

DOC: describe how to create a test environment with tox - #15878

Merged
pllim merged 2 commits into
astropy:mainfrom
mhvk:devdocs-testguide-editable-install
Mar 18, 2024
Merged

pllim merged 2 commits into
astropy:mainfrom
mhvk:devdocs-testguide-editable-install

Conversation

@mhvk

@mhvk mhvk commented Jan 12, 2024

Copy link
Copy Markdown
Contributor

Add a description to the test guide with a handy way to use tox to create a virtual environment with all the test packages nicely set up. As asked by @taldcroft in #10303 (comment)

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@mhvk mhvk added the Docs label Jan 12, 2024
@mhvk mhvk added this to the v6.1.0 milestone Jan 12, 2024
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but we cannot check for it on Actions; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@mhvk

mhvk commented Jan 12, 2024

Copy link
Copy Markdown
Contributor Author

We had a lot of discussion in #10394 about this, which I did not revisit as somehow I thought this was the elegant better solution that was then not possible, instead of the one I already tried to add at that time. Anyway, if there is a better solution now, happy to adopt it. But if not, let's get this time-saver in...

@mhvk
mhvk requested review from Cadair, astrofrog and saimn January 12, 2024 19:43
@saimn

saimn commented Jan 15, 2024

Copy link
Copy Markdown
Contributor

With tox 4 tox --develop now works as expected (it can be run multiple times), so why not documenting this instead ?

@mhvk

mhvk commented Jan 15, 2024

Copy link
Copy Markdown
Contributor Author

With tox 4 tox --develop now works as expected (it can be run multiple times), so why not documenting this instead ?

Because it is way slower. I just happened to have an enviroment set up:

time tox -e test --develop --notest
real    0m9.485s
user    0m8.405s
sys     0m1.550s
source .tox/test/bin/activate

time pytest astropy/utils/masked/tests/test_function_helpers.py::TestSpaceFunctions
real    0m1.080s
user    0m1.088s
sys     0m0.238s

10 s for not even running any test (I don't know how to select just one) vs 1 s matters if you are trying to debug something.

@taldcroft taldcroft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhvk - Let's get this in! I made a couple comments.

Comment thread docs/development/testguide.rst Outdated
Comment on lines +119 to +120
tox -e test --develop --notest
source .tox/test/bin/activate

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest documenting using all dependencies by default in development. The incremental cost is low and running all those tests locally is good.

Suggested change
tox -e test --develop --notest
source .tox/test/bin/activate
tox -e test-alldeps --develop --notest
source .tox/test-alldeps/bin/activate

@taldcroft taldcroft Mar 15, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I tested this from a clean Python 3.11 conda env and it worked well and is fast. It only requires installing tox, nothing more beyond these commands, so I think that's a win.

I have an idea to write a Quickstart section to provide one simple workflow as a prelude to the rest of the detailed options here, but getting this PR merged will be a big step forward.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense. Indeed, I often end up doing pip install ipython to do some more interactive debugging, and this will just pull that in too.

and this works for ``.rst`` files too::
or::

pytest astropy/units/tests/test_quantity.py::TestQuantityCreation::test_float_dtype_promotion

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine but in practice I would always do something shorter like pytest astropy/units -k float_dtype.
Maybe combine all these into examples in a single block of examples:

You can also specify a single directory, a file (Python or ``.rst`` doc file), or a specific test
to check from the commandline, e.g.::

    pytest astropy/modeling
    pytest astropy/wcs/tests/test_wcs.py
    pytest astropy/units -k float_dtype_promotion
    pytest astropy/units/tests/test_quantity.py::TestQuantityCreation::test_float_dtype_promotion
    pytest astropy/wcs/index.rst

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The long form has the advantage of tab completion for just the file, and copy & paste from pytest output... But your suggestion of a slew of examples is best!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest has documentation about test selection and there is no reason we shouldn't link to that and only highlight the differences here. As far as I can tell there are two differences:

  1. Thanks to pytest-doctestplus it is possible to run tests in docstrings of all .py files and tests in all .rst files.
  2. Thanks to pytest-filter-subpackage it is possible to run all tests related to a package (e.g. wcs) with pytest -P wcs, whereas without the plugin the equivalent invocation would be pytest {astropy,docs}/wcs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but that the page linked to is substantially longer than the simple list yet does not provide much beyond it. In these development docs, I feel we should just help people get going.

That said, obviously can include the link...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've pushed an extra commit with both links (learned about -k and --lf now...). I added [skip ci] to the last commit to avoid running all tests again when the docs will do, but obviously fine to squash the commits.

@mhvk
mhvk force-pushed the devdocs-testguide-editable-install branch from b8b363c to 0126518 Compare March 15, 2024 13:37
@mhvk

mhvk commented Mar 15, 2024

Copy link
Copy Markdown
Contributor Author

@taldcroft - thanks! I pushed a new version with your changes.

@taldcroft taldcroft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me!

@taldcroft

Copy link
Copy Markdown
Member

With tox 4 tox --develop now works as expected

This is great! I previously couldn't find the docs but now I see. Cool.

@mhvk

mhvk commented Mar 16, 2024

Copy link
Copy Markdown
Contributor Author

@pllim - would you be able to merge? I used skip ci since this is docs only, but had forgotten it means it needs a merge override... @taldcroft approved.

@pllim

pllim commented Mar 18, 2024 •

Copy link
Copy Markdown
Member

Sure thing. Sorry for the delayed response. I usually don't work in the weekends (if I can help it).

@pllim
pllim merged commit b95b7cc into astropy:main Mar 18, 2024
@mhvk

mhvk commented Mar 18, 2024

Copy link
Copy Markdown
Contributor Author

@pllim - and you shouldn't! I didn't mean my message to convey any sense of hurry - just that I couldn't do the merge myself (and that I don't presume you would be looking out for approved PRs stalled because of skip ci!!).

@mhvk
mhvk deleted the devdocs-testguide-editable-install branch March 18, 2024 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants