fix: Skip tests when running without dependencies from the root (griffe) - #485
Conversation
When running tests within `griffelib` alone as root, importing `griffecli` and `mkdocstrings` at module level causes `ModuleNotFoundError`. Defer these imports and guard them with `pytest.importorskip()` so the tests skip gracefully instead of failing.
3174f6b to
888f85a
Compare
|
more errors showing up. let me look into it. |
|
Thanks! Looks like the test errors are unrelated to your changes (too old actions?). Let me try to fix them. |
|
LGTM! Feel free to move out of draft when you're ready, and I'll squash-merge 🙂 Thanks! |
8526b24 to
a11d24c
Compare
|
Hit a few more errors while running test with griffelib as the root. I think I also added the optional test dependencies for Thank you so much for reviewing and working on this with me! Let me know if you like the changes or not. 😁 |
| # The 'pypi' extra provides dependencies needed for the load_pypi functionality | ||
| # to download and inspect packages from PyPI. | ||
| pypi = ["pip>=24.0", "platformdirs>=4.2", "wheel>=0.42"] | ||
| test = ["pytest>=8.2", "pytest-gitconfig>=0.8.0", "jsonschema>=4.18"] |
There was a problem hiding this comment.
Can we set these as dev-dependencies instead? I'm not yet sold on declaring development dependencies as extras.
There was a problem hiding this comment.
I'm actually leaning more toward your idea - put the test deps in the dev-dependencies. It's just because I saw so many packages is using %pyproject_buildrequires -x test, but the newer "%pyproject_buildrequires -g test" does exist so there shouldn't be any blocker for making them as dev-dependencies. 😁 I'll go ahead and move these dependencies to dev-deps.
|
Thanks!
Do you mean there's room for improving the setup here, rather than just excluding the extension?
It's only fair! Thanks for packaging the project for Fedora! |
a11d24c to
3c1826f
Compare
TBH, I think you know more about the module import in python than me. I don't really think I can give you any constructive advices. It's just from my point of view I think Anyway, it should be good to go. Thanks again! 😁 |
|
We depend on griffe-inherited-docstrings for the documentation of the public API. If we don't load it in our public API tests, I think it doesn't matter because the impacted tests aren't run since I suppose there's no objects.inv in your packaging/testing environment. It's an official extension, we have control over it, so breaking changes are not something to worry about too much 🙂 OK, merging! |
|
Woops, should have been a |
…iffe) When running tests within `griffelib` alone as root, importing `griffecli` and `mkdocstrings` at module level causes `ModuleNotFoundError`. Defer these imports and guard them with `pytest.importorskip()` so the tests skip gracefully instead of failing. Issue-484: #484 PR-485: #485 Co-authored-by: Timothée Mazzucotelli <dev@pawamoy.fr>
I see.
Yes, you're right. There is no objects.inv in the packaging environment. 😁 Thanks! It's a pleasure to work with you! 😁 |
For reviewers
Description of the change
When running tests within
griffelibalone as root, importinggriffecliandmkdocstringsat module level causesModuleNotFoundError. Defer these imports and guard them withpytest.importorskip()so the tests skip gracefully instead of failing.Introducing those two dependencies to
griffelibto just being able to run these tests does not seem like a reasonable choice. Therefore, the best solution I can think of is to gracefully bypass those tests.I can also bypass those tests by manually skip them while running pytest but I feel like the tests come with the package should be error-free.
Relevant resources