Repository navigation
Fix modules in anticipation of future testing updates - #6450
Conversation
This manifests itself during the test collection phase of pytest (when invoked directly from the command line). It seems like during test collection 'locals' gets polluted and so it is not a reliable way to load the parameters into the module's namespace.
|
Hi there @drdavella 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labelled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃. Everything looks good from my point of view! 👍 |
|
Thanks! I propose we wait until we have made a decision about invoking tests from pytest before moving ahead with this. |
|
IMHO the |
|
CircleCI failure is very cryptic for me: |
|
@astrofrog, @pllim I actually think the |
|
@pllim maybe restart and 🙏 for success? The travis failure appeared to be unrelated but I see it's already been restarted. |
|
Re: CircleCI -- I don't have admin access to that but I think @astrofrog does. |
|
Btw, I'm in the process of creating an issue that is sort of a testing manifesto, so hopefully it can be used to spur some discussion in advance of the coordination meeting (which hopefully I'll be able to attend). |
|
I think these changes are good independent of anything related to pytest, and would suggest just merging them. My only question is whether a changelog entry is even necessary. |
|
p.s. @drdavella - thanks for looking at this in detail - I actually quite like the idea of having tests run directly with pytest, and, independently, very much like the cleanup of the testing code you are doing. |
|
|
|
Re: Change log -- I agree that it is not necessary. The change is not something typical user would notice or care about. |
|
I just reverted the change log (oops forgot [ci skip], sorry). I can squash if you want. |
|
Let's wait to squash until this PR is approved. For future reference, you can also do a |
|
Travis failed again :( |
| ) | ||
|
|
||
| available = tuple(k for k in locals() if not k.startswith('_')) | ||
| # If new parameters are added, this list must be updated |
There was a problem hiding this comment.
Looking at this again, why not keep the autogeneration, but just ensure it works? E.g.,
available = [k for k in locals() if isinstance(k, dict) and 'reference' in k]
(I'd also remove the explicit addition from core.__all__ and instead write there __all__ = [...] + parameters.available or add them in the loop further down, but that is a bit beyond this PR...)
There was a problem hiding this comment.
This seems reasonable but I worry that it might be a little unreliable. What is the chance of randomly having another dict in your namespace with a member named reference? Maybe it's not huge but it doesn't seem impossible.
It almost seems like each of these should be an instance of a new class like cosmology.Parameter or something like that (which would inherit dict), and then the test would be as simple as:
available = [k for k in locals() if isinstance(k, Parameter)]
But maybe that's too much of a change?
There was a problem hiding this comment.
If one had a class, it would be quite trivial to have it have a registry as well. But probably overkill, and then it gets even further away from the primary purpose of this PR... The logic for my suggestion was that it keeps the code more similar but still allows for not having to delete imports.
There was a problem hiding this comment.
Also, in either case, since locals() returns a dictionary, it will need to look like the following:
all_locals = locals()
available = [k for k in all_locals if isinstance(all_locals[k], WhateverClass)]
There was a problem hiding this comment.
At the risk of being called stubborn, I updated the auto-generation with a simple class-based scheme. It seems pretty clean and introduced a minimal and largely invisible change, but I can do it the other way if that seems more reasonable.
|
While dealing with my remaining comment, maybe rebase and get rid of the two changelog commits? |
5285f58 to
d52f5f6
Compare
| # __all__ in core.py | ||
| # in addition to the list above. | ||
|
|
||
| class Parameter(dict): |
There was a problem hiding this comment.
If we keep this, maybe it should be called Cosmology. Doh.
|
Current failures are real. I didn't test against Py2 before pushing. Working on a fix. |
|
I'm not sure what to make of the repeated travis failures. It seems to be the same test every time. I really don't see how any of these changes could have that effect, but I don't know. Is it possible that a particular travis VM is just flaky? Would a particular VM instance be bound to the same test case every time? |
|
Exactly the same problem is happening for other PRs, so it is unrelated (@bsipocz?). I'd much prefer not to introduce a new class in this PR. At least I won't merge it without asking for the cosmology maintainer's input, and it seems quite possible we'll end up bikeshedding. But up to you. |
|
Re: Travis failure -- Doesn't look related. Probably flaky connection to astropy data server at that time. |
|
To be honest, I feel like using a class is the 'right' way to accomplish this, because it guarantees that you get what you ask for. It seems Pythonic. The other approach is a heuristic that could backfire, however small that probability is, and could lead in the future to bug that would be pretty hard to diagnose. But maybe I'm just paranoid. However, as you say, we've spent enough time bikeshedding, and I don't want to be any more of a hard head than I have already. My vote at the moment is just to revert to using an explicit list of cosmologies but update |
|
Sounds good. Am all in favour of not needlessly updating multiple lists with the same information! |
2549faa to
071e714
Compare
|
OK, this looks all OK now, so I'll merge. Thanks, @drdavella! I'm also looking forward to the rest of the pytest simplifications - right now what we have only works on pytest 3.1! (#6418) |
Clean-up modules, partially in anticipation of future testing simplifications.
In anticipation of eventually being able to invoke tests directly from pytest (and other testing updates), it is necessary to fix a few quirks in the way that packages are structured and modules are loaded.
Like #6449, these changes are based on work from #6437. Even if that PR is not integrated as-is, this is a necessary update.