Skip to content

Describe how to do development within a tox testing environment - #10394

Closed
mhvk wants to merge 2 commits into
astropy:mainfrom
mhvk:docs-dev-test-with-tox
Closed

mhvk wants to merge 2 commits into
astropy:mainfrom
mhvk:docs-dev-test-with-tox

Conversation

@mhvk

@mhvk mhvk commented May 25, 2020

Copy link
Copy Markdown
Contributor

As promised in #10303, once we found out how to easily set up an environment for testing, I would add it to the documentation. This is meant to do that. In the process, I also saw an annoying note about py.test instead of pytest so I went through an removed all out-of-date references.

I'm not 100% sure about whether there shouldn't be references to this elsewhere...

fixes #10303

@pllim

This comment has been minimized.

@saimn

saimn commented May 26, 2020

Copy link
Copy Markdown
Contributor

@pllim - tox works in conda, what error do you get ?

@pllim

This comment has been minimized.

@pllim

pllim commented May 28, 2020

Copy link
Copy Markdown
Member

Huh... I try the tox stuff in my conda env again and things work. The only difference is I have recently blew that old env away and created a new one. conda can be such a mystery sometimes. Anyway, I'll hide my comment above. Sorry for the noise!

@pllim pllim 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.

Nice clean-up. Thanks!

@pllim

This comment has been minimized.

Comment thread docs/development/testguide.rst Resolved

@pllim pllim 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.

Need to know how to deactivate tox env.

development and then use direct ``pytest`` commands within that environment.
For instance::

tox -e test-alldeps --develop --notest

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.

Is this really something that we should be recommending? It seems like a very weird way to spin up a virtualenv and people might end up here in all manner of weird ways and not really understand what they are doing, (i.e. virtualenv inside conda etc).

The justification from the sentence below is:

Now, one can run any of the pytest commands below to only run tests that are relevant to the development one is doing.

You can already customise the pytest behaviour by passing extra args to the tox command, and you can skip the (slow) sdist creation and build with the --develop flag. I really think this should at least come with a large health warning on the top. I see the utility if you really have to debug a failure in one specific tox env and you really want to get in there with a python interpreter, but I really struggle to see the justification for doing this to run anything but the most spectacularly complex pytest commands.

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.

@Cadair - this came from real life problems from experienced developers (@mhvk and myself) having trouble just being able to run tests in an agile manner. What we need is a way to be able to have a one-time setup that reproduces accurately the travis test environment and then be able to re-run tests (over and over again, sometimes) in a few seconds, ala:

pytest astropy/time --pdb -k test_darn_its_still_failing

In discussions referenced in #10303, this was the best we came up with. If you have a better suggestion, please do tell!! That would be great. You can see already below that I also am not quite happy with the conda/virtualenv mixture that is likely coming out of this.

@taldcroft taldcroft May 29, 2020 •

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.

And note there are still outstanding problems with pytest as far as I can tell. If I just blindly install pytest, that gives me 5.4.0 and the dreaded error in test collection:

E   pytest.PytestDeprecationWarning: direct construction of DocTestModulePlus has been deprecated, please use DocTestModulePlus.from_parent

Maybe I'm doing something wrong, but if I am having problems that means others may be in the same boat.

The point being that pinning certain packages (which happens in the tox setup) can be important.

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.

@taldcroft - what version of pytest-doctestplus are you using? The issues should be fixed with v0.7.0

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 was using 0.5. On conda (astropy / conda-forge) the latest available seems to be 0.6.1.

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.

@Cadair - yes, if there is a good way just with tox, that would be preferable! The one advantage of the present suggestion is that it shows, indirectly, a bit how tox actually works.

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.

The suggested workaround on the tox issue is to put the build deps from pyproject.toml into the deps= list in tox.ini which does seem to work, although isn't an ideal solution imo.

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.

There is a tox rewrite underway, I just asked upstream if the bug will be properly addressed in the new version 🤞🏽

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.

@Cadair, @astrojuanlu - this PR got stuck because my recommendation for fast testing with tox --develop --no-test and then enabling the virtual environment was clearly not ideal, but on the other hand there didn't seem to be a good alternative. I see that @Cadair's tox issue tox-dev/tox#1595 has been closed because this is fixed in "the rewrite branch", though I think that implies tox 4, which is not out yet. It certainly still fails with ~current tox.

Since it now has been more than a year with no other effective solution, my sense is to get this PR in and revisit when there is a better solution. But I'm also happy to just let it auto-close - after all, my own work flow is now fine...

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.

My feeling is that tox 4 is "almost there", but that can still mean a few months. This is a net improvement on the current docs, so I'm 👍🏽 on getting it in.

Comment thread docs/development/testguide.rst Outdated

Now, one can run any of the ``pytest`` commands below to only run tests that
are relevant to the development one is doing. If the development includes
documentation, one could install the documentation dependencies in the same

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.

There is one catch, if I have things right, namely the graphviz dependency which must come either via conda or via a separate system-wide install. So for this pip-centric workflow you cannot imply all the docs dependencies are part of the "environment".

Now on Mac, doing a system install of graphviz requires either homebrew or macports. I don't use either of those. So then for me that means making a base environment with conda and then a tox-generated virtualenv under that. This leads me to have a command line prompt like (base) (test-alldeps) which is a bit unseemly to me.

So despite having agreed the tox-virtualenv might be a good way forward, I have stopped using it in favor of just making a conda environment that has the right deps using #10343.

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.

I have removed the documentation part, as this could just make things harder than easier.

Comment thread docs/development/testguide.rst Outdated
---------------------------------------------

As noted, running ``tox`` can be quite slow, yet it has the advantage over the
other methods that it puts together a consistent set of dependencies. One can

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
mhvk force-pushed the docs-dev-test-with-tox branch from 07f5dd9 to cf422d6 Compare October 23, 2020 19:34
@mhvk

mhvk commented Oct 23, 2020

Copy link
Copy Markdown
Contributor Author

I updated this small PR to describe how to do development within a tox environment, since my sense would be that it is better to have something reasonable rather than nothing. But fine also to close or postpone.

@bsipocz
bsipocz requested a review from Cadair October 26, 2020 23:52
@bsipocz

bsipocz commented Oct 26, 2020

Copy link
Copy Markdown
Member

Could a tox enthusiast say a final say on this? maybe @Cadair?

@pllim

pllim commented Apr 28, 2021

Copy link
Copy Markdown
Member

Yes, would be nice if @Cadair or @saimn can have a final look at this, since it is all about tox.

@saimn

saimn commented Apr 28, 2021

Copy link
Copy Markdown
Contributor

tox4 should fix that (tox-dev/tox#1945) so maybe we wait a little more ?

@mhvk
mhvk force-pushed the docs-dev-test-with-tox branch from cf422d6 to a7ce964 Compare September 3, 2021 19:22
@github-actions

github-actions Bot commented Sep 4, 2021

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 10 hours. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@pllim

pllim commented Sep 4, 2021 •

Copy link
Copy Markdown
Member

this pull request hasn't had any new commits for approximately 10 hours.

LoL... looks like bot still a little buggy. I'll investigate. 😬

Update: Hopefully I fixed the bug. Sorry about that!

@pllim pllim removed the Close? Tell stale bot that this issue/PR is stale label Sep 4, 2021
@astrofrog astrofrog removed this from the v5.0 milestone Nov 1, 2021
@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Feb 1, 2022
@github-actions

github-actions Bot commented Feb 2, 2022

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@astrojuanlu

Copy link
Copy Markdown
Member

tox4 will release a beta soonish tox-dev/tox#2298 I'm already using the latest alpha for all my projects and it does solve a number of issues. Maybe this can hold off a couple if months?

@pllim pllim removed the Close? Tell stale bot that this issue/PR is stale label Feb 2, 2022
@pllim

pllim commented Feb 2, 2022

Copy link
Copy Markdown
Member

Sure, I removed the Close? label but it doesn't really reset the clock unless @mhvk rebase.

@mhvk

mhvk commented Feb 2, 2022

Copy link
Copy Markdown
Contributor Author

Yes, absolutely fine to wait a bit longer - would be nice to have a more elegant solution!

@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Feb 3, 2022
@github-actions

github-actions Bot commented Feb 4, 2022

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 5 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@github-actions

github-actions Bot commented Mar 7, 2022

Copy link
Copy Markdown
Contributor

I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks!

If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here.

@github-actions github-actions Bot added the closed-by-bot Closed by stale bot label Mar 7, 2022
@github-actions github-actions Bot closed this Mar 7, 2022
@astrojuanlu

Copy link
Copy Markdown
Member

@taldcroft

Copy link
Copy Markdown
Member

I needed this documentation today, too bad it is only available in a closed PR...

Use case - tricky test failure that only shows up for numpy 1.18 (pydev-test-oldestdeps), so I want to use the VS code debugger an editable install to see what's going on. Any advice @Cadair on the "right" way to do this efficiently?

@taldcroft

Copy link
Copy Markdown
Member

You can already customise the pytest behaviour by passing extra args to the tox command, and you can skip the (slow) sdist creation and build with the --develop flag

Am I doing something wrong?

(astropy) ➜  astropy git:(table-aggregate-mixins) ✗ tox -e pydev-test-oldestdeps --develop -- -k mixins_unsupport

Traceback (most recent call last):
  File "setup.py", line 66, in <module>
    from extension_helpers import get_extensions  # noqa
ModuleNotFoundError: No module named 'extension_helpers'
ERROR: invocation failed (exit code 1)
_________________________________________________ summary _________________________________________________
ERROR:   pydev-test-oldestdeps: InvocationError for command /Users/aldcroft/git/astropy/.tox/pydev-test-oldestdeps/bin/python setup.py --name (exited with code 1)

@taldcroft taldcroft reopened this Mar 29, 2022
@pllim pllim removed Close? Tell stale bot that this issue/PR is stale closed-by-bot Closed by stale bot labels Mar 29, 2022
@pllim

pllim commented Mar 29, 2022

Copy link
Copy Markdown
Member

The bot will mark this as stale again unless you rebase, FYI.

@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Mar 30, 2022
@Cadair

Cadair commented Mar 30, 2022

Copy link
Copy Markdown
Member

Am I doing something wrong?

No, this is the bug that caused this PR to stall out. Tox doesn't support doing this with build deps. tox-dev/tox#1595

I am happy to put the sequence of commands in this diff in the documentation, but I think the surrounding justification is misleading. We should be recommending people do this is the case where they really need an environment controlled by tox to debug an issue with CI etc, and link to the tox bug / explain why you can't do --develop with tox.

On a related note, the infrastructure team should probably start porting our plugins to tox 4...

@taldcroft

Copy link
Copy Markdown
Member

@Cadair - ah, thanks for the explanation. So maybe following the transition to tox4 we can revisit this...

@taldcroft taldcroft closed this Mar 30, 2022
@Cadair

Cadair commented Dec 7, 2022

Copy link
Copy Markdown
Member

Tox 4 has been released today (and broke all our CI), when we have adapted our config for tox 4 etc we should be able to revisit this.

@mhvk
mhvk deleted the docs-dev-test-with-tox branch August 26, 2023 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Close? Tell stale bot that this issue/PR is stale Docs no-changelog-entry-needed testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request: way to have development testing set up with pinned test dependencies

8 participants