-
Notifications
You must be signed in to change notification settings - Fork 0
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
imports in coherent.test mask project under test #3
Comments
I'm watching activity on pfmoore/editables and I didn't want to derail the conversation there, so I will ask here. I saw your wrote this:
Do I understand correctly that you want the tests to run on the sources rather than an installed version of the current project? Isn't it generally recommended against to test the sources directly, as it could hide potential packaging issues? |
Love the engagement!
Yes. For several reasons.
It could potentially hide packaging issues. And in fact it's happened to me many times that I've tested a change, got everything to pass, then committed and pushed upstream only to find that a new file wasn't added to the commit. However, this scenario isn't necessarily fixed by installing (as the build might pick up the file even if it's not under source control), and it's almost always caught in CI prior to any release. I've found it exceedingly rare that a change will pass checks in CI but still have packaging issues, especially after adopting Moreover, with the Coherent System, I'm really aiming to take these concerns out of the users' hands. I'd like to provide some modestly-opinionated choices and clear guidance such that a user is unlikely to mess up packaging. For example, the current implementation includes all files and data in the package (with special exclusions for I want to eliminate the foot guns (required config knobs) and duplicative steps (adding a file with MANIFEST.in + VCS) and provide an experience that's easy to get right and intuitive. Due to the reasons enumerated above, it's more intuitive for a developer to test their sources than to test their installed product, so in general, I prefer/advise to stick to one copy of the sources. That said, an editable install doesn't necessarily have the right fidelity and certainly has limitations (especially with regard to built extensions and or any solution that relies on installer behaviors to function, such as .pth files, cache warming, etc), so I'm not ready to declare testing the installed version off limits, but I am willing to discourage it where it's not needed. And in cases where it is needed or valuable, I recommend to have a separate set of tests (perhaps akin to integration tests) that test the installed package, which can be local or in CI, but don't interact with the main test suite. |
I should also point out that this issue exists under the current regime, which does test the modules as installed (as there's not yet support for editable installs of coherent projects). |
Thank you, that makes sense. I believe my own tests actually run against source files and not a non-editable installed version of my project. And it's working fine. I did make packaging mistakes in the past, forgetting to include files in dists, or misconfiguring the dists builder, that the tests didn't catch. But nowadays, with my templated projects, this just doesn't happen anymore. If Coherent's build and test systems ensure that, then yes, the convenience of editable installs outweighs recommendations. Also you're right, it makes sense t have additional integration tests that specifically check that dists are built as expected. |
Let me know what direction you're thinking of heading. |
In 7b3cc9a, I've drafted a fix to clean the imports, but this approach unfortunately doesn't work for So maybe the best option would be to always launch pytest in a subprocess. That would be the cleanest way to get a clean set of sys.modules for that invocation. Other options I'm considering:
|
In the past, mkdocstrings introspected objects in the same process, and had to force reload sys modules when sources changed. This didn't work well with some packages like Numpy (we were computing the sys.modules diff from one iteration to the other to unload everything) who failed the second time because of some low-level memory initialization I suppose. I don't think it's insurmountable. I just opted to run a subprocess instead at the time, which was much easier. |
In 761e182, I implement the subprocess-based approach. It's more involved because of all the wrapping behaviors that have to happen:
It was so much more elegant to let all of those behaviors just fall through. |
This feedback is really useful. In this particular case, since the imports are largely under the control of the coherent system, there's opportunity to limit the modules to those that work well in such a situation. But I agree, it would be better to be able to avoid imposing these cross-project constraints (i.e. if |
Isolation is good! |
When running
coherent.test
, it importspip_run
andcoherent.build
:coherent.test/__main__.py
Lines 5 to 6 in b20a402
And then runs pytest in-process:
coherent.test/__main__.py
Lines 13 to 15 in b20a402
As a result, when testing
coherent.build
orpip-run
or any of their dependencies, it will not get current code in the project under test, even though it was just installed, because the modules are already loaded into sys.modules.I can think of a couple of possible approaches:
As a temporary workaround, I'm invoking
coherent.test
with an explicit early dependency on.
so the local build shows up and is used for coherent.test (and thus gets used by pytest):The text was updated successfully, but these errors were encountered: