Skip to content

Testing/test runner refactor - #4020

Merged
embray merged 6 commits into
astropy:masterfrom
embray:testing/test-runner-refactor
Oct 5, 2015
Merged

embray merged 6 commits into
astropy:masterfrom
embray:testing/test-runner-refactor

Conversation

@embray

@embray embray commented Jul 30, 2015

Copy link
Copy Markdown
Member

Following discussion in #2317, here's some changes that will make it I think a little easier to add changes to the astropy.tests test runner. This also moves the AstropyTest distutils command class back into astropy.tests so that it isn't awkwardly separated in astropy-helpers. There will be an associated change in astropy-helpers, so this PR should include a submodule update before it's merged.

This PR depends on #4017.

@Cadair

Cadair commented Jul 30, 2015

Copy link
Copy Markdown
Member

so sunpy has a subclass of the AstropyTest class, in which I have defined our own arguments, mainly to fiddle the online offline options. I am assuming that this, and the respective changes in astropy_helpers would mean that our test command would have to import astropy first??

https://github.com/sunpy/sunpy/blob/master/sunpy/tests/setup_command.py

@embray

embray commented Jul 30, 2015

Copy link
Copy Markdown
Member Author

@Cadair That's right. You won't have to make that change immediately though. The old command class will be kept for backwards compat for now.

Maybe instead though you could describe what you mean by "fiddle the online offline options". Could that just be included in the test runner?

@embray
embray force-pushed the testing/test-runner-refactor branch from e825a7e to 34e9691 Compare July 30, 2015 15:09
@Cadair

Cadair commented Jul 30, 2015

Copy link
Copy Markdown
Member

So, when I moved sunpy over to ah the testing infrastructure was a bit of a botch, I wanted to keep our previous online mark behaviour from pytest i.e. -k online / -k-online so I rigged up a --online and --online-only flag in the TestHelper https://github.com/sunpy/sunpy/blob/master/sunpy/tests/setup_command.py#L30.

I was discussing with @bsipocz that our runner probably needs re-writing because we seem to be having some issues with the doctest build stalling on travis, and as I said it's a bit of a hack.

How would I change these options from the test runner?

@bsipocz

bsipocz commented Jul 30, 2015

Copy link
Copy Markdown
Member

@Cadair - or there may be no need to rewrite stuff if it will be easy to just add extra options (like the planned --slow). You could just patch --online on top of the ah/astropy test suite and the rest would work as is.

Thus I guess all the astropy doctest directives would work out of the box and solve sunpy/sunpy#1456 and the halting builds, etc.

@embray

embray commented Jul 30, 2015

Copy link
Copy Markdown
Member Author

This should make it easier to add new options, yes.

On the astropy-helpers end of things, it will work so that even if you don't have astropy available there is still a dummy "test" command, so users can see that it's available. It just won't work if astropy isn't installed (and it says as much if you try to use it).

Also, @mdboom and I were talking possibly at some point pulling the astropy testing helpers out to a separate package (not part of astropy-helpers, but something else). I don't have an ETA on that though.

Comment thread astropy/__init__.py

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For the affiliated package template we may need something slightly ugly here along the lines of:

try:
    from astropy.tests.runner import TestRunner
    test = TestRunner.make_test_runner_in(__path__[0])
except ImportError:
    def test(*args, **kwargs):
        """Run the package test suit.  Requires the astropy package to be installed."""
        raise RuntimeError("The astropy package must be installed in order to run the tests.")

@Cadair

Cadair commented Jul 30, 2015

Copy link
Copy Markdown
Member

So how does this make it easier to add new options to the TestHelper for flags to setup.py?

@embray

embray commented Jul 31, 2015

Copy link
Copy Markdown
Member Author

Did you mean "for" or "or"?

Adding options to setup.py is still treated independently from the TestRunner class, for a number of reasons. But by being in the same package it means all options added to the test command are supported and implemented in the TestRunner. Since the test command is just a thin wrapper around TestRunner they're intrinsically coupled and belong together.

@embray

embray commented Jul 31, 2015

Copy link
Copy Markdown
Member Author

In other words, it's "easier" in the sense that you only have to make changes in one or two places (all in astropy.tests) and don't have to orchestrate a corresponding change in astropy-helpers, and then have to make sure that the correct version of astropy-helpers is always used to support whatever options you're adding.

If you want to subclass you just have to subclass astropy.tests.runner.TestRunner and astropy.tests.command.AstropyTest, and you can rest assured that those classes are in sync with each other as far as what features they support. In retrospect it was a mistake to separate those classes (and only those classes) into separate packages.

@embray embray added this to the v1.1.0 milestone Sep 10, 2015
@embray

embray commented Sep 10, 2015

Copy link
Copy Markdown
Member Author

If there are no objections, this should be included in v1.1.0. To be clear: this doesn't have any effect in terms of backwards-compatibility.

@embray

embray commented Sep 16, 2015

Copy link
Copy Markdown
Member Author

[rebased on master]

@embray

embray commented Sep 17, 2015

Copy link
Copy Markdown
Member Author

Hmm, not clear at all why this blew up so badly. Need to rebase again, then we'll see...

@embray
embray force-pushed the testing/test-runner-refactor branch from d16f9ff to ea172ba Compare September 17, 2015 19:50
@embray
embray force-pushed the testing/test-runner-refactor branch from ea172ba to c388b90 Compare September 28, 2015 17:50
@astrofrog

Copy link
Copy Markdown
Member

@embray - can you rebase? Do you want to get this into 1.1?

@embray
embray force-pushed the testing/test-runner-refactor branch from c388b90 to 9d82db6 Compare September 29, 2015 14:43
@embray

embray commented Sep 29, 2015

Copy link
Copy Markdown
Member Author

Rebased and fixed indentation problem.

going on here:

1) The TestRunner class has been moved out of astropy.tests.helper
into its own module astropy.tests.runner.

2) The astropy.tests.__init__ module has been cleaned up so that there
isn't anything imported into the top level of the astropy.tests
namespace.  In particular astropy.tests.helper is not imported.  This is
so that astropy.tests.runner can be imported without causing pytest to
be imported too.

3) Added a TestRunner.make_test_runner_in classmethod--this actually
*creates* the test() function that is called as astropy.test().  It
gets its docstring and arguments from TestRunner.run_tests (this is
in contrast to the previous situation where TestRunner.run_tests and
astropy.test got different information from each other, and arguments
signatures had to be specified in two different places).

4) Added astropy.tests.command module containing the AstropyTest
setup.py command implementation (moved back from astropy-helpers).
In retrospect it was a mistake to keep this separately in
astropy-helpers, because the functionality of the test command is very
much tied to what capabilities are available in the test runner, so that
having them in separate projects made it difficult to keep them in sync.
An associated change will be added to astropy-helpers to add a wrapper
that attempts to import the test command from astropy (and will provide
a fallback if it is unavailable).

5) Changed how the astropy.__init__ namespace is cleaned up.
embray added 5 commits October 1, 2015 10:13
…and in any case the function we're wrapping doesn't *have* any annotations in the first place).
…eral previous fixes from other PRs. Also updated astropy.tests.command to incorporate the changes from astropy/astropy-helpers#190
@embray
embray force-pushed the testing/test-runner-refactor branch from fe90935 to db8aaa6 Compare October 1, 2015 18:58
@embray

embray commented Oct 2, 2015

Copy link
Copy Markdown
Member Author

Wow, this is finally ready to merge \o/

Anyone want to review this before I do?

Comment thread astropy/tests/__init__.py

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.

Should we consider this as being part of the public API and therefore keep the last import?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, it's never been documented as such. I don't think this import being here was ever particularly deliberate, and nobody seems to rely on it.

@astrofrog

Copy link
Copy Markdown
Member

Apart from my small comment above, this is good to go 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants